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 <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

typedef complex<double> P;

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

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

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

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 proj(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 refl(const L &l, const P &p) {
  return p + 2.0 * (proj(l, p) - p);
}

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]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

bool intersectSP(const L &s, const P &p) {
	//cout<<abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0])<<endl;
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

int n;
double ans;
P s,g;
L M[6];

void f(int time,int pre,int* ref){
	L m[6];
	rep(i,n)m[i]=M[i];
	double res=0;
	P goal=g,point[8];
	rep(i,time){
		goal=refl(m[ref[time-1-i]],goal);
	}
	L laser=L(s,goal);
	point[0]=s;
	L line[7][6];
	rep2(i,1,time+1){
		rep(j,n)line[i-1][j]=m[j];
		if(!intersectSS(laser,m[ref[i-1]]))goto fail;
		point[i]=crosspoint(laser,m[ref[i-1]]);
		for(int j=i-2;j>=0;j--){
			point[i]=refl(line[j][ref[j]],point[i]);
		}
		if(i<time){
			rep(j,n)if(j!=ref[i-1]){
				rep(k,2)m[j][k]=refl(m[ref[i-1]],m[j][k]);
			}
		}
	}
	//rep(i,time)cout<<ref[i]<<" ";cout<<goal<<endl;
	point[time+1]=g;
	//rep(i,time+2)cout<<point[i]<<(i<time+1?"-":"");cout<<endl;
	
	rep(i,time){
		if(intersectSS(L(point[i],point[i+2]),M[ref[i]]))goto fail;
	}
	
	rep(i,time+1){
		rep(j,n){
			if(i>0&&j==ref[i-1]||i<time&&j==ref[i]){
				//cout<<i<<" "<<j<<"cont"<<intersectSS(L(point[i],point[i+1]),m[j])<<endl;
				//cout<<point[i]<<"-"<<point[i+1]<<" "<<m[j][0]<<" "<<m[j][1]<<endl;
				//cout<<intersectSP(m[j],point[1])<<endl;
				continue;
			}
			if(intersectSS(L(point[i],point[i+1]),M[j]))goto fail;
		}
	}
	
	//cout<<"OK ";
	rep(i,time+1)res+=abs(point[i+1]-point[i]);//,cout<<point[i+1]-point[i]<<" "<<abs(point[i+1]-point[i])<<" ";
	//cout<<res<<endl;
	ans=min(ans,res);
	fail:;
	if(time<5){
		rep(i,n)if(i!=pre){
			*(ref+time)=i;
			f(time+1,i,ref);
		}
	}
}

int main(){
	//cout<<intersectSS(L(P(24,64),P(-40,0)),L(P(0,10),P(-12,30)))<<endl;
	//cout<<crosspoint(L(P(24,64),P(-40,0)),L(P(0,10),P(-12,30)))<<endl;
	//cout<<crosspoint(L(P(72,77),P(7,10)),L(P(55.2192,0),P(55.2192,100)))<<endl;
	while(cin>>n && n){
		rep(i,n){
			double x,y,xx,yy;
			cin>>x>>y>>xx>>yy;
			M[i]=L(P(x,y),P(xx,yy));
		}
		double tx,ty,lx,ly;
		cin>>tx>>ty>>lx>>ly;
		s=P(lx,ly),g=P(tx,ty);
		ans=INF;
		int ref[6];
		f(0,-1,ref);
		cout<<setprecision(15)<<ans<<endl;
	}
}