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 <cmath>

using namespace std;

double eps = 1e-7;

struct point{
    double x,y;
    
    point(){}
    point(double _x, double _y) : x(_x), y(_y) {}
    
    point operator + (point P){
        return point(x + P.x,y + P.y);
    }
    
    point operator - (point P){
        return point(x - P.x,y - P.y);
    }
    
    point operator * (double t){
        return point(x * t,y * t);
    }
    
    double dot(point P){
        return x * P.x + y * P.y;
    }
    
    double cross(point P){
        return x * P.y - y * P.x;
    }
    
    double dist(point P){
        return sqrt((x - P.x) * (x - P.x) + (y - P.y) * (y - P.y));
    }
}s,e,M[5][2];

int n,ind[6];

double area(point a, point b, point c){
    return a.x * b.y + b.x * c.y + c.x * a.y - a.y * b.x - b.y * c.x - c.y * a.x;
}

bool cross(point a, point b, point c, point d){
    return area(a,b,c) * area(a,b,d) < eps && area(c,d,a) * area(c,d,b) < eps;
}

point intersection(point a, point b, point c, point d){
    return a + (b - a) * ((c - a).cross(d - c) / (b - a).cross(d - c));
}

point projection(point x, point a, point b){
    return a + (b - a) * ((x - a).dot(b - a) / (b - a).dot(b - a));
}

point reflection(point x, point a, point b){
    return x + (projection(x,a,b) - x) * 2;
}

bool check(int m, point E){
    int prev = -1,cur;
    point S = s;
    
    for(int i = m - 1;i >= 0;--i){
        cur = ind[i];
        
        if(!cross(S,E,M[cur][0],M[cur][1])) return false;
        
        point X = intersection(S,E,M[cur][0],M[cur][1]);
        
        for(int j = 0;j < n;++j)
            if(j != prev && j != cur && cross(S,X,M[j][0],M[j][1]))
                return false;
        
        S = X;
        E = reflection(E,M[cur][0],M[cur][1]);
        prev = cur;
    }
    
    for(int j = 0;j < n;++j)
        if(j != prev && cross(S,E,M[j][0],M[j][1]))
            return false;
    
    return true;
}

double ans;

void dfs(int m, int last){
    if(m == 6) return;
    
    point e2 = e;
    
    for(int i = 0;i < m;++i)
        e2 = reflection(e2,M[ ind[i] ][0],M[ ind[i] ][1]);
    
    if(check(m,e2)) ans = min(ans,s.dist(e2));
    
    for(int i = 0;i < n;++i){
        if(i != last){
            ind[m] = i;
            dfs(m + 1,i);
        }
    }
}

int main(){
    ios::sync_with_stdio(0);
    
    while(true){
        cin >> n;
        
        if(n == 0) break;
        
        for(int i = 0;i < n;++i)
            cin >> M[i][0].x >> M[i][0].y >> M[i][1].x >> M[i][1].y;
        
        cin >> s.x >> s.y;
        cin >> e.x >> e.y;
        
        ans = 1e15;
        
        dfs(0,-1);
        
        cout << fixed << setprecision(4) << ans << '\n';
    }
    
    return 0;
}