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

const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : VP{
    L(const P& a, const P& b){ resize(2); at(0)=a; at(1)=b; }
    L(){ resize(2); }
};

namespace std{
	bool operator < (const P &a, const P &b){
		return (a.X!=b.X)? a.X<b.X : a.Y<b.Y;
	}
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}

int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) <-EPS) return -1; //cw
    if(dot(b,c) < EPS) return +2; //c-a-b
    if(norm(b) < norm(c)) return -2; //a-b-c
    return 0; //a-c-b
}
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 );
}
bool strictItsSS(const L& s, const L& t){
    return ( ccw(s[0],s[1],t[0]) *ccw(s[0],s[1],t[1]) == -1 ) &&
        ( ccw(t[0],t[1],s[0]) *ccw(t[0],t[1],s[1]) == -1);
}

P projection(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 reflection(const L& l, const P& p) {
  return p + 2.0*(projection(l, p) -p);
}
 
P crosspointLL(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]);
  return m[0] + B /A *(m[1]-m[0]);
}
bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}


vector<int> idx(10, -1);
double solve(int step, int end, P s, P g, vector<vector<L> > &wall){
    if(step==end){
    	VP cp(step+2);
    	cp[0]=s; cp[step+1]=g;
        L ray(s,g);
        bool flag = true;
        for(int i=1; i<=step; i++){
            if(!isParallel(ray, wall[i][idx[i]]) && strictItsSS(ray, wall[i][idx[i]])){
                cp[i] = crosspointLL(ray, wall[i][idx[i]]);
            }else{
            	flag = false;
            	break;
            }
        }
        if(flag){
        	for(int i=0; i<=step; i++){
        		if((s<g && cp[i+1]<cp[i]) || (g<s && cp[i]<cp[i+1])){
        			flag = false;
        			break;
        		}
        	}
        }
        
        if(flag){
        	for(int i=0; i<=step; i++){
        		L cut_ray(cp[i], cp[i+1]);
        		for(int j=0; j<(int)wall[0].size(); j++){
        			if(j==idx[i] || j==idx[i+1]) continue;
        			if(intersectSS(cut_ray, wall[i][j])){
        				flag = false;
        				break;
        			}
        		}
        	}
        }
        
        if(flag){
            return abs(g-s);
        }else{
            return INF;
        }
    }
    
    double ans = INF;
    for(int i=0; i<(int)wall[0].size(); i++){
        if(idx[step]==i) continue;
        idx[step+1] = i;
        for(int j=0; j<(int)wall[0].size(); j++){
            wall[step+1][j] = L(reflection(wall[step][i], wall[step][j][0]), reflection(wall[step][i], wall[step][j][1]));
        }
        ans = min(ans, solve(step+1, end, s, reflection(wall[step][i], g), wall));
        idx[step+1] = -1;
    }
    return ans;
}

double search(P s, P g, vector<vector<L> > &wall){
    double ans = INF;
    for(int i=0; i<6; i++){
        ans = min(ans, solve(0,i,s,g,wall));
    }
    return ans;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        
        vector<vector<L> > wall(6, vector<L>(n));
        for(int i=0; i<n; i++){
            for(int j=0; j<2; j++){
                double x,y;
                cin >> x >> y;
                wall[0][i][j] = P(x,y);
            }
        }
        double sx,sy,gx,gy;
        cin >> gx >> gy >> sx >> sy;
        P s(sx,sy), g(gx, gy);

        cout << fixed;
        cout << setprecision(10);
        cout << search(s,g,wall) << endl;
    }
    return 0;
}