#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;
}

Measured memory_bytes: 1268