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 <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;

typedef long double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos((R)(-1));

/*
 -1 -> neg
  0 -> near 0
  1 -> pos
  */
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}

/*
 -1 -> a > b
 0 -> a near b
 1 -> a < b
 */
int sgn(R a, R b) {
    return sgn(b-a);
}

bool near(P a, P b) {
    return !sgn(abs(a-b));
}

bool lessP(const P &l, const P &r) {
    if (sgn(l.real(), r.real())) return l.real() < r.real();
    if (sgn(l.imag(), r.imag())) return l.imag() < r.imag();
    return false;
}

R cross(P a, P b) { return a.real()*b.imag() - a.imag()*b.real(); }
R dot(P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }

/* 1->cclock
  -1->clock
   0->on
   2->back
  -2->front
  */
int ccw(P a, P b, P c) {
    assert(!near(a, b));
    if (near(a, c) || near(b, c)) return 0;
    int s = sgn(cross(b-a, c-a));
    if (s) return s;
    if (dot(b-a, c-a) < 0) return 2;
    if (dot(a-b, c-b) < 0) return -2;
    return 0;
}

R ssqrt(R d) {
    d = max<R>(0, d);
    return sqrt(d);
}

R sacos(R d) {
    d = max<R>(-1, d);
    d = min<R>(1, d);
    return acos(d);
}

struct L {
    P x, y;
    L() {};
    L(P x, P y) :x(x), y(y) {};
};

P vec(const L &l) {
    return l.y - l.x;
}

R abs(const L &l) {
    return abs(vec(l));
}


R distLP(const L &l, const P &p) {
    return abs(cross(vec(l), p-l.x)/abs(vec(l)));
}


int crossLL(const L &l, const L &m, P &r) {
    L mm = L(m.x - l.x, m.y - l.x);
    mm.x *= polar<R>(1.0, -arg(vec(l)));
    mm.y *= polar<R>(1.0, -arg(vec(l)));
    if (sgn(vec(mm).imag()) == 0) {
        r = l.x;
        if (sgn(mm.x.imag()) == 0) return -1;
        return 0;
    }
    r = mm.x - vec(mm) * (mm.x.imag() / vec(mm).imag());
    r *= polar<R>(1.0, arg(vec(l)));
    r += l.x;
    return 1;
}

int crossSS(const L &l, const L &m, P &r) {
    int u = crossLL(l, m, r);
    if (u == 0) return 0;
    if (u == -1) {
        int x = ccw(l.x, l.y, m.x);
        int y = ccw(l.x, l.y, m.y);
        if (x == 0) {
            r = m.x;
            return -1;
        }
        if (y == 0) {
            r = m.y;
            return -1;
        }
        if (x == y) return 0;
        r = l.x;
        return -1;
    }
    if (ccw(l.x, l.y, r) == 0 && ccw(m.x, m.y, r) == 0) return 1;
    return 0;
}

int n;
P s, e;
L l[5];
int hist[6];
R mi;

P mirror(const P &p, const L &l) {
    if (ccw(l.x, l.y, p) > 0) {
        return p - polar(2*distLP(l, p), arg(vec(l)*P(0, 1)));
    } else {
        return p + polar(2*distLP(l, p), arg(vec(l)*P(0, 1)));
    }
}

L mirror(const L &tar, const L &l) {
    return L(mirror(tar.x, l), mirror(tar.y, l));
}

void dfs(int p) {
    P ee = e;
    L lt[6][5];
    for (int i = 0; i < n; i++) {
        lt[0][i] = l[i];
    }
    for (int i = 1; i <= p; i++) {
        for (int j = 0; j < n; j++) {
            lt[i][j] = mirror(lt[i-1][j], lt[i-1][hist[i-1]]);
        }
        ee = mirror(ee, lt[i-1][hist[i-1]]);
    }
/*    printf("debug print: (");
    for (int i = 0; i < p; i++) {
        printf("%d, ", hist[i]);
    }
    printf(") ");
    cout << ee << endl;*/
    bool f = true;
    R back = 0, now;
    for (int i = 0; i < p; i++) {
        P pp;
        if (crossSS(L(s, ee), lt[i][hist[i]], pp) != 1) {
            f = false;
            break;
        }
        now = abs(s-pp);
        if (now <= back) {
            f = false;
            break;
        }
        for (int j = 0; j < n; j++) {
            if (i && j == hist[i-1]) continue;
            if (j == hist[i]) continue;
            if (crossSS(L(s, ee), lt[i][j], pp) == 1) {
                if (back < abs(s-pp) && abs(s-pp) < now) {
//                    printf("error %d %d\n", i, j);
                    f = false;
                    break;
                }
            }
        }
        back = now;
    }
    if (abs(s-ee) <= back) {
        f = false;
    }
    for (int i = 0; i < n; i++) {
        if (p && hist[p-1] == i) continue;
        P pp;
        if (crossSS(L(s, ee), lt[p][i], pp) == 1) {
            if (back < abs(s-pp) && abs(s-pp) < abs(s-ee)) {
    //            printf("error %d\n", i);
                f = false;
                break;
            }
        }
    }

    if (f) {
        mi = min(mi, abs(s - ee));
    }

    if (p == 5) return;
    for (int i = 0; i < n; i++) {
        if (p && i == hist[p-1]) continue;
        hist[p] = i;
        dfs(p+1);
    }
}

bool solve() {
    cin >> n;
    if (!n) return false;
    for (int i = 0; i < n; i++) {
        R x1, y1, x2, y2;
        cin >> x1 >> y1 >> x2 >> y2;
        l[i] = L(P(x1, y1), P(x2, y2));
    }
    R sx, sy, ex, ey;
    cin >> ex >> ey >> sx >> sy;
    s = P(sx, sy);
    e = P(ex, ey);
    mi = 1e9;
    dfs(0);
    assert(mi < 1e8);
    printf("%.20Lf\n", mi);
    return true;
}


int main() {
    while (solve()) {}
    return 0;
}