Problem: A laser beam generator, a target object and some mirrors are placed on a plane. The mirrors stand upright on the plane, and both sides of the mirrors are flat and can reflect beams. To point the beam at the target, you may set the beam to several directions because of different reflections. Your job is to find the shortest beam path from the generator to the target and answer the length of the path.

Figure G-1 shows examples of possible beam paths, where the bold line represents the shortest one.

<image>

Figure G-1: Examples of possible paths

Input

The input consists of a number of datasets. The end of the input is indicated by a line containing a zero.

Each dataset is formatted as follows. Each value in the dataset except n is an integer no less than 0 and no more than 100.

> n
>  PX1 PY1 QX1 QY1
>  ...
>  PXn PYn QXn QYn
>  TX TY
>  LX LY
>

The first line of a dataset contains an integer n (1 ≤ n ≤ 5), representing the number of mirrors. The following n lines list the arrangement of mirrors on the plane. The coordinates (PXi, PYi) and (QXi, QYi) represent the positions of both ends of the mirror. Mirrors are apart from each other. The last two lines represent the target position (TX, TY) and the position of the beam generator (LX, LY). The positions of the target and the generator are apart from each other, and these positions are also apart from mirrors.

The sizes of the target object and the beam generator are small enough to be ignored. You can also ignore the thicknesses of mirrors.

In addition, you can assume the following conditions on the given datasets.

* There is at least one possible path from the beam generator to the target.
* The number of reflections along the shortest path is less than 6.
* The shortest path does not cross or touch a plane containing a mirror surface at any points within 0.001 unit distance from either end of the mirror.
* Even if the beam could arbitrarily select reflection or passage when it reaches each plane containing a mirror surface at a point within 0.001 unit distance from one of the mirror ends, any paths from the generator to the target would not be shorter than the shortest path.
* When the beam is shot from the generator in an arbitrary direction and it reflects on a mirror or passes the mirror within 0.001 unit distance from the mirror, the angle θ formed by the beam and the mirror satisfies sin(θ) > 0.1, until the beam reaches the 6th reflection point (exclusive).



Figure G-1 corresponds to the first dataset of the Sample Input below. Figure G-2 shows the shortest paths for the subsequent datasets of the Sample Input.

<image>

Figure G-2: Examples of the shortest paths

Output

For each dataset, output a single line containing the length of the shortest path from the beam generator to the target. The value should not have an error greater than 0.001. No extra characters should appear in the output.

Sample Input


2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0


Output for the Sample Input


180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809






Example

Input

2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0


Output

180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;

const double EPS = 1e-9;
typedef complex<double> P;


int n;
struct L : public vector<P>{
	L(P a,P b){
		push_back(a);
		push_back(b);
	}
};

double dot(P a,P b){
	return real(a*conj(b));
}

double cross(P a,P b){
	return imag(a*conj(b));
}


int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;	// a ??? b ??§???????¨??????????????????? b ??? c(???)
	if (cross(b, c) < 0)   return -1;	// a ??? b ??§????¨??????????????????? b ??? c(???)
	if (dot(b, c) < 0) return +2;    	// a???b??§????????????a??????????¶???????b???c(c--a--b)
	if (norm(b) < norm(c)) return -2;	// a???b??§????????????b???c(a--b--c)
	return 0;							// a???b??§????????????b???c(????????? b == c)
}

P projection(const L &l, const P &p) {
	double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
	return l[0] + t*(l[0]-l[1]);
}

P reflection(const L &l, const P &p) {
	return p + 2.0 * (projection(l, p) - p);
}

bool intersectSS(const L &s,const L &t){
 	return 	ccw(s[0],s[1],t[0]) * ccw(s[0],s[1],t[1]) <= 0 && 
			ccw(t[0],t[1],s[0]) * ccw(t[0],t[1],s[1]) <= 0;
}
P crosspoint(const L &l, const L &m) {
	double A = cross(l[1] - l[0], m[1] - m[0]);
	double B = cross(l[1] - l[0], l[1] - m[0]);
	if (abs(A) < EPS && abs(B) < EPS) return m[0];
	return m[0] + B / A * (m[1] - m[0]);
}

P in(){
	double x,y;
	cin >> x >> y;
	return P(x,y);
}



struct Instance{
	P s,g;
	vector<L> ls;
};


double ans;
int debug;
double test(const vector<Instance> &c,vector<int> id){
	/*
	if( id != vector<int>{0,1,0,1,0} ) return 1e9;
	
	//cout << id[0] << endl;
	//cout << c.front().s << "->" << c.back().g << endl;
	cout << "new instance[";
	for(int j : id ) cout << j << " ";
	cout << "]" << endl;
	for(int i = 0 ; i < c.size() ; i++){
		cout << "___" << i << "th___" << endl;
		cout << "start: " << c[i].s << endl;
		cout << "goal: " << c[i].g << endl;
		
		if( i == debug ){
			fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",c.front().s.real(),c.front().s.imag(),c.back().g.real(),c.back().g.imag());
			for( auto j : c[i].ls ){
				fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",j[0].real(),j[0].imag(),j[1].real(),j[1].imag());
				//cout << j[0] << "-" << j[1] << endl;
			}
		}
	}
	//*/
	
	
	P cur = c.front().s;
	P t = c.back().g;
	int idx = -1;
	double ans = abs(cur-t);
	for(int i = 0 ; i < c.size() ; i++){
/*
		fprintf(stderr,"circle(%.2lf,%.2lf)\n",cur.real(),cur.imag());
		fprintf(stderr,"circle(%.2lf,%.2lf)\n",		t.real(),t.imag());

		if( i == debug ){
			fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",c.front().s.real(),c.front().s.imag(),c.back().g.real(),c.back().g.imag());
			for( auto j : c[i].ls ){
				fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",j[0].real(),j[0].imag(),j[1].real(),j[1].imag());
				//cout << j[0] << "-" << j[1] << endl;
			}
		}
//*/
		vector< pair<double,int> > dst;
		P nextp;
		for(int j = 0 ; j < n ; j++){
			if( idx == j ) continue;
			
			if( intersectSS(c[i].ls[j],L(cur,t)) ){
				P cp = crosspoint(L(cur,t),c[i].ls[j]);
				if( i < id.size() and j == id[i] ) nextp = cp;
				dst.push_back({abs(cur-cp),j});
				//cout << cur << "-" << t << " " << c[i].ls[j][0] << "-" << c[i].ls[j][1] << " " << cp << '(' << j << " [" << i << "]" << "btw, " << abs(cur-cp) << endl;
			}
		}
		sort(dst.begin(),dst.end());
		assert( !dst.size() or dst.front().first > 1e-9 );
		if( i < id.size() ){
//			cout << "ll" << dst.front().first << endl;
			if( dst.size() == 0 ){
				//cout << "fail must hit " << id[i] << " but no hit" << endl;
				return 1e9;
			}
			if( dst.front().second != id[i] ){
				//cout << "fail must hit " << id[i] << " but " << dst.front().second << endl;
				return 1e9;
			}
			cur = nextp;
		}else{
		
			if( dst.size() != 0 ){
				//cout << "fail some wall exits" << endl;
				return 1e9;
			}
		}
		if( i < id.size() ) {
			idx = id[i];
		}
		
	}
	
	//*/
	//exit(0);
	return ans;
}


void dfs(vector<Instance> c,int ref,vector<int> ids){
	
	if(ref < 0 ) return;
	ans = min(ans,test(c,ids));
	
	for(int i = 0 ; i < n ; i++){
		if( ids.size() and ids.back() == i ) continue;
		Instance d = c.back();
		vector<int> nid = ids;
		d.s = reflection(c.back().ls[i],c.back().s);
		d.g = reflection(c.back().ls[i],c.back().g);
		nid.push_back(i);
		vector<Instance> newc = c;
		
		for(int j = 0 ; j < n ; j++){
			d.ls[j][0] = reflection(c.back().ls[i],c.back().ls[j][0]);
			d.ls[j][1] = reflection(c.back().ls[i],c.back().ls[j][1]);
		}
		newc.push_back(d);
		dfs(newc,ref-1,nid);
	}
}
int main(int argc,char *vvv[]){
	//if( argc >= 2 ){
	//	debug = atoi(vvv[1]);
	//}
	while(cin >> n && n){
		ans = 1e18;
		Instance inp;
		for(int i = 0 ; i < n ; i++){
			P a = in();
			P b = in();
			inp.ls.push_back(L(a,b));
		}
		inp.g = in();
		inp.s = in();
		dfs({inp},5,{});
		printf("%.10lf\n",ans);
		//cerr << "TODO:" << 5 << endl;
	}
}