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 <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#define EPS 1e-9
#define INF 1e10

using namespace std;

class L;

class P{
public:
	double x,y;
	P(){x=0;y=0;}
	P(double x, double y){this->x=x;this->y=y;}
	P reflect(L l);
	void print(){
		printf("P(%.1lf,%.1lf)\n", x, y);
	}
};
class L{
public:
	P p1,p2;
	L(){}
	L(P p1, P p2){this->p1=p1;this->p2=p2;}
	L reflect(L l);
	void print(){
		printf("L(P(%.1lf,%.1lf)->P(%.1lf,%.1lf))\n", p1.x, p1.y, p2.x, p2.y);
	}
};

P P::reflect(L l){
	double dx = (l.p2.x - l.p1.x), dy = (l.p2.y - l.p1.y);
	double a = dx * dx + dy *dy, b = dx * (l.p1.x - x) + dy * (l.p1.y - y);
	double t = -b / a;
	double tx = l.p1.x + dx * t, ty = l.p1.y + dy * t;
//	printf("reflect t=(%lf,%lf)\n", tx,ty);
	
	this->x = 2*tx-x;
	this->y = 2*ty-y;
	return *this;
}
L L::reflect(L l){
	this->p1.reflect(l);
	this->p2.reflect(l);
	return *this;
}


int isIntersect(L l1, L l2){
//printf("isintersect(%.0lf, %.0lf)(%.0lf, %.0lf), (%.0lf,%.0lf)(%.0lf,%.0lf)\n", l1.p1.x, l1.p1.y, l1.p2.x, l1.p2.y, l2.p1.x, l2.p1.y, l2.p2.x, l2.p2.y);
	if (((l1.p1.x - l1.p2.x) * (l2.p1.y - l1.p1.y) + (l1.p1.y - l1.p2.y) * (l1.p1.x - l2.p1.x)) * 
		((l1.p1.x - l1.p2.x) * (l2.p2.y - l1.p1.y) + (l1.p1.y - l1.p2.y) * (l1.p1.x - l2.p2.x)) < 0){
		if (((l2.p1.x - l2.p2.x) * (l1.p1.y - l2.p1.y) + (l2.p1.y - l2.p2.y) * (l2.p1.x - l1.p1.x)) * 
			((l2.p1.x - l2.p2.x) * (l1.p2.y - l2.p1.y) + (l2.p1.y - l2.p2.y) * (l2.p1.x - l1.p2.x)) < 0	){
			return 1;
		}
	}
	return 0;
}

P getIntersect(L l1, L l2){
//	double S1 = ((l2.p2.x - l1.p2.x) * (l1.p1.y - l1.p2.y) - (l2.p2.y - l1.p2.y) * (l1.p1.x - l1.p2.x)) / 2;
//	double S2 = ((l2.p2.x - l1.p2.x) * (l1.p2.y - l2.p1.y) - (l2.p2.y - l1.p2.y) * (l1.p2.x - l2.p1.x)) / 2;
//	printf("%lf, %lf\n", S1,S2);
//	return P(l1.p1.x + (l2.p1.x - l1.p1.x) * S1 / (S1 + S2 + EPS), l1.p1.y + (l2.p1.y - l1.p1.y) * S1 / (S1 + S2 + EPS));

	double S1 = ((l2.p2.x - l2.p1.x) * (l1.p1.y - l2.p1.y) - (l2.p2.y - l2.p1.y) * (l1.p1.x - l2.p1.x)) / 2;
	double S2 = ((l2.p2.x - l2.p1.x) * (l2.p1.y - l1.p2.y) - (l2.p2.y - l2.p1.y) * (l2.p1.x - l1.p2.x)) / 2;
	return P(l1.p1.x + (l1.p2.x - l1.p1.x) * S1 / (S1 + S2 + EPS), l1.p1.y + (l1.p2.y - l1.p1.y) * S1 / (S1 + S2 + EPS));
}


L mir[6][6];
P start, tgoal;
int n;
double ans;
void check(vector <int> ref){
	int i,j;
	P goal = tgoal;
//	cout << "check " << ref.size() << endl;
//	goal.print();
	for(i=0;i<int(ref.size());i++){
		for(j=0;j<n;j++){
			mir[i+1][j] = mir[i][j];
			if(ref[i]!=j) mir[i+1][j].reflect(mir[i][ref[i]]);
		}
//		mir[i][ref[i]].print();
		goal.reflect(mir[i][ref[i]]);
//		goal.print();
	}
	P cur = start;
	P is;
	for(i=0;i<=int(ref.size());i++){
		L laser = L(cur, goal);
		if(i != int(ref.size())){
			if(!isIntersect(laser, mir[i][ref[i]])){
//				printf("not intersect %d, %d\n", i, ref[i]);
				return;
			}
			is = getIntersect(laser, mir[i][ref[i]]);
		}else is = goal;
		laser.p2 = is;
		for(j=0;j<n;j++){
			if((i == int(ref.size()) || ref[i]!= j) &&
			   (!i || ref[i-1]!= j) &&
			    isIntersect(laser, mir[i][j])){
//				printf("intersect %d, %d\n", i, j);
//				laser.print();
//				mir[i][j].print();
				return;
			}
		}
		
		cur = is;
	}
//	cout << "success " << sqrt	((goal.x-start.x)*(goal.x-start.x)+(goal.y-start.y)*(goal.y-start.y)) << endl;
	ans = min(ans, (goal.x-start.x)*(goal.x-start.x)+(goal.y-start.y)*(goal.y-start.y));
}

void solve(vector<int> ref){
	int i;

	check(ref);
	if(ref.size()<5){
		for(i=0;i<n;i++){
			if(ref.size() && ref[ref.size()-1] == i) continue;
			ref.push_back(i);
			solve(ref);
			ref.pop_back();
		}
	}
}

int main(){
	int i,x1,y1,x2,y2;
	vector<int> ref;

//	getIntersect( L(P(0,0),P(1,1)), L(P(1,0),P(0,1)) ).print();
//	P(0,100).reflect(L(P(60,30),P(60,95))).print();
//	return 0;

	while(cin>>n,n){
		ans = 1e9;
		for(i=0;i<n;i++){
			cin>>x1>>y1>>x2>>y2;
			mir[0][i] = L(P(x1,y1),P(x2,y2));
		}
		cin>>tgoal.x>>tgoal.y>>start.x>>start.y;
		
		ref.clear();
		solve(ref);
		cout << sqrt(ans) << endl;
	}
}