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 <cstdio>
#include <iostream>
#include <vector>
#include <algorithm>
#include <complex>
#include <cmath>
#include <cfloat>
using namespace std;

#define EPS 1e-7

typedef complex<double> P;

int n;
vector<P> pts;
double ans;

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

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

double intersect(P pa1, P pa2, P pb1, P pb2){
	P da12 = pa2 - pa1;
	P db21 = pb1 - pb2;
	P dab1 = pb1 - pa1;
	double D = cross(da12, db21);
	if(abs(D) > EPS){
		double t = cross(dab1, db21) / D;
		double s = cross(da12, dab1) / D;
		if(EPS < t && t < 1.0 - EPS && EPS < s && s < 1.0 - EPS){
			return t;
		}
	}
	return DBL_MAX;
}

void reflect(vector<P> &p, P mr1, P mr2){
	P u = mr1 - mr2;
	u /= abs(u);
	
	for(int i = 1; i < p.size(); ++i){
		p[i] = 2.0 * (mr1 - dot(mr1 - p[i], u) * u) - p[i];
	}
}

void check(P to, const vector<int> &seq){
	vector<P> p = pts;
	double dist = abs(to - p[0]);
	if(dist >= ans){ return; }

	P from = p[0];
	for(int k = 0; ; ++k){
		double minr = 1.0;
		int idx = 0;
		for(int i = 1; i <= n; ++i){
			double r = intersect(from, to, p[i*2], p[i*2+1]);
			if(minr > r){
				minr = r;
				idx = i;
			}
		}

		if(k == seq.size()){
			if(idx == 0){ ans = dist; }
			break;
		}
		else if(seq[k] != idx){
			break;
		}
		reflect(p, p[idx*2], p[idx*2+1]);
		from += minr * (to - from);
	}
}

void dfs(const vector<P> &p, vector<int> &seq){
	check(p[1], seq);
	
	if(seq.size() < 5){
		for(int i = 1; i <= n; ++i){
			vector<P> q = p;
			reflect(q, p[i*2], p[i*2+1]);
			seq.push_back(i);
			dfs(q, seq);
			seq.pop_back();
		}
	}
}

int main(){
	int x, y;
	while(scanf("%d", &n), n){
		pts.resize(2 * n + 2);
		for(int i = 0; i < 2 * n; ++i){
			scanf("%d%d", &x, &y);
			pts[i+2] = P(x, y);
		}
		scanf("%d%d", &x, &y);
		pts[1] = P(x, y);
		scanf("%d%d", &x, &y);
		pts[0] = P(x, y);

		ans = DBL_MAX;
		vector<int> seq;
		dfs(pts, seq);
		printf("%f\n", ans);
	}
}