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:
// ACM-ICPCà\I2010 G. [U[õÌ½Ë

#include <iostream>
#include <vector>
#include <complex>

using namespace std;

typedef complex<double> P;

struct L {
	P p, q;
	L(P p, P q) : p(p), q(q) {}
};

const double EPS = 1e-8;
const double INF = 1e12;

double dot(P a, P b) { return real(conj(a)*b); }
double cross(P a, P b) { return imag(conj(a)*b); }
double angle(P a, P b) { return arg(conj(a)*b); }

P footPerp(L l, P p) {
	return l.p + (l.q-l.p)*(dot(l.q-l.p, p-l.p) / (abs(l.q-l.p)*abs(l.q-l.p)));
}

P lineShadow(L l, P p){
	return 2.0*footPerp(l, p)-p;
}

bool ssIntersect(L a, L b){
	if(abs(imag((a.q-a.p)/(b.q-b.p)))<EPS) return false;
	return cross(a.q-a.p, b.p-a.p)*cross(a.q-a.p, b.q-a.p) < 0 &&
    	   cross(b.q-b.p, a.p-b.p)*cross(b.q-b.p, a.q-b.p) < 0;
}

bool lpIntersect(L a, P p){
	return abs(imag((p-a.p)/(a.q-a.p)))<EPS;
}

P ssCrosspoint(L a, L b){
	double A = cross(a.q-a.p, b.q-b.p);
	double B = cross(a.q-a.p, a.q-b.p);
	return b.p + B/A * (b.q-b.p);
}

void check(vector<double> &agl, const vector<L> &vl, const vector<int> &idx, P s, P g){
	for(int i=0;i<idx.size();i++){
		if(lpIntersect(vl[idx[i]], g)) return ;
		g = lineShadow(vl[idx[i]], g);
	}
	agl.push_back(angle(P(1,0), g-s));
}

void dfs(vector<double> &agl, const vector<L> &vl, vector<int> &idx, P s, P g){
	check(agl, vl, idx, s, g);
	if(idx.size()==5) return ;
	for(int i=0;i<vl.size();i++){
		if(!idx.empty()&&idx.back()==i) continue;
		idx.push_back(i);
		dfs(agl, vl, idx, s, g);
		idx.pop_back();
	}
}

double calc(const vector<double> &agl, const vector<L> &vl, P s, P g){
	double res = INF;
	for(int i=0;i<agl.size();i++){
		P cur = s;
		P dir = P(cos(agl[i]), sin(agl[i]));
		double len = 0.0;
		for(int cnt=0; ;cnt++){
			P nxt = cur + 1000.0*dir;
			if(lpIntersect(L(cur, cur+dir), g)&&dot(dir, g-cur)>EPS) nxt = g;
			int idx = -1;
			for(int j=0;j<vl.size();j++){
				if(!lpIntersect(vl[j], cur)&&ssIntersect(L(cur, nxt), vl[j])){
					idx = j;
					nxt = ssCrosspoint(L(cur, nxt), vl[j]);
				}
			}
			len += abs(cur-nxt);
			if(abs(nxt-g)<EPS) break;
			if(idx == -1 || cnt == 6){
				len = INF;
				break;
			}
			dir = lineShadow(L(nxt, nxt+(vl[idx].q-vl[idx].p)*P(0,1)), cur) - nxt;
			dir /= abs(dir);
			cur = nxt;
		}
		res = min(res, len);
	}
	return res;
}

int main(){
	int n;
	while(cin >> n, n){
		P s, g;
		vector<L> vl;
		for(int i=0;i<n;i++){
			int px, py, qx, qy; cin >> px >> py >> qx >> qy;
			vl.push_back(L(P(px,py), P(qx,qy)));
		}
		int tx, ty, lx, ly; cin >> tx >> ty >> lx >> ly;
		s = P(tx, ty);
		g = P(lx, ly);
		vector<int> idx;
		vector<double> vd;
		dfs(vd, vl, idx, s, g);
		printf("%.4lf\n", calc(vd, vl, s,g));
	}
}