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<cmath>
#include<utility>
#include<vector>
#include<complex>
#include<algorithm>

using namespace std;

typedef double Real;
typedef complex<Real> Point;
typedef pair<Point,Point> Line;
typedef pair<Point,Point> Segment;
typedef vector<Point> Polygon;

const Real eps=1e-6;
const Real inf=1e9;

Point NPoint=Point(NAN,NAN);

void print(Point p,char ch='\n'){
	printf("(%f %f)%c",p.real(),p.imag(),ch);
}

template<class T> bool eq(T a,T b){
	return abs(a-b)<eps;
}

template<class T> int sgn(T a){
	if(eq(a,(Real)0)) return 0;
	if(a>0) return 1;
	return -1;
}

bool onSeg(Point a,Point b,Point c){
	return eq(abs(a-b),abs(a-c)+abs(c-b));
}

bool onSeg(Segment s,Point p){
	return onSeg(s.first,s.second,p);
}

Real doP(Point a,Point b){
	return (conj(a)*b).real();
}

Real crP(Point a,Point b){
	return (conj(a)*b).imag();
}

Point proj(Point p,Point b){
	return b*doP(p,b)/norm(b);
}

bool isPara(Point a,Point b){
	return eq(crP(a,b),(Real)0);
}

bool isPara(Line l1,Line l2){
	return isPara(l1.second-l1.first,l2.second-l2.first);
}

Point perp(Line l,Point a){
	Point p=l.first,q=l.second;
	return p+proj(a-p,q-p);
}

Point refl(Line l,Point p){
	Point h=perp(l,p);
	return h*(Real)2-p;
}

Point iLL(Line l1,Line l2){
	if(isPara(l1,l2)) return NPoint;
	Point a1=l1.first,b1=l1.second;
	Point a2=l2.first,b2=l2.second;
	Real num=crP(a2-a1,b1-a1);
	Real den=crP(b1-a1,b2-a2);
	return a2+(b2-a2)*(num/den);
}

Point iSS(Segment s1,Segment s2){
	Point p=iLL(s1,s2);
	if(isnan(p.real())) return p;
	if(onSeg(s1,p)&&onSeg(s2,p)) return p;
	return NPoint;
}


int N;
vector<Segment> ms;
Point s,t;

vector<vector<int> > rs;

bool is_valid(Point cs,Point ct,int dep){
	if(dep==6) return false;
	Point p=NPoint;
	Real d=inf;
	Point nt=ct;
	for(int i=0;i<N;i++){
		Segment seg=ms[i];
		Segment cur=Segment(cs,ct);
		Point cp=iSS(seg,cur);
		if(isnan(cp.real())) continue;
		if(eq(cp,cs)) continue;
		Real cd=abs(cs-cp);
		if(cd<d){
			d=cd;
			p=cp;
			nt=refl(seg,ct);
		}
	}
	if(isnan(p.real())){
		if(eq(t,ct)) return true;
		return false;
	}
	bool flg=is_valid(p,nt,dep+1);
	return flg;
}

Real solve(vector<int> rs){
	Point s=::s,t=::t;
	for(int i=(int)rs.size()-1;i>=0;i--){
		Segment seg=ms[rs[i]];
		t=refl(seg,t);
	}
	if(is_valid(s,t,0)) return abs(s-t);
	return inf;
}

void dfs(vector<int> &vec,int cur,int t){
	if(cur==t){
		rs.push_back(vec);
		return;
	}
	for(int i=0;i<N;i++){
		vec.push_back(i);
		dfs(vec,cur+1,t);
		vec.pop_back();
	}
}

void gen(){
	vector<int> tmp;
	rs.clear();
	for(int i=0;i<=5;i++){
		tmp.clear();
		dfs(tmp,0,i);
	}
}

Real solve(){
	gen();
	Real res=inf;
	for(int i=0;i<rs.size();i++){
		Real cur=solve(rs[i]);
		res=min(res,cur);
	}
	return res;
}

Point readPoint(){
	Real x,y;
	scanf("%lf%lf",&x,&y);
	return Point(x,y);
}

void input(){
	ms.clear();
	scanf("%d",&N);
	if(N==0) exit(0);
	for(int i=0;i<N;i++){
		Point p,q;
		p=readPoint();
		q=readPoint();
		ms.push_back(Segment(p,q));
	}
	t=readPoint();
	s=readPoint();
}

int main(){
	while(true){
		input();
		Real ans=solve();
		printf("%f\n",ans);
	}
	return 0;
}