#include <bits/stdc++.h>
using namespace std;


using ld = long double;

constexpr ld eps = 1e-8;


namespace geometry2d {


using point = std::complex<long double>;
using polygon = std::vector<point>;


bool eq(long double a, long double b) {
    return (std::abs(a-b) < eps);
}


long double dot(point a, point b) {
    return std::real(std::conj(a) * b);
}

long double cross(point a, point b) {
    return std::imag(std::conj(a) * b);
}


class segment {
public:
    segment()
        : a(point(0, 0)),
          b(point(0, 0))
    {}
    segment(point a_, point b_)
        : a(a_), b(b_)
    {}

    point a, b;
};

class line {
public:
    line()
        : a(point(0, 0)), b(point(0, 0))
    {}
    line(point a_, point b_)
        : a(a_), b(b_)
    {}
    line(segment s)
        : a(s.a), b(s.b)
    {}

    point a, b;
};

class circle {
public:
    circle()
        : p(point(0, 0)), r(0)
    {}
    circle(point p_, long double r_)
        : p(p_), r(r_)
    {}

    point p;
    long double r;
};


int ccw(point a, point b, point c) {
    b -= a; c -= a;
    if(cross(b, c) > eps)           return 1;  // a -> b -> c : counterclockwise
    if(cross(b, c) < -eps)          return -1; // a -> b -> c : clockwise
    if(dot(b, c) < 0)               return 2;  // c -> a -> b : line
    if(std::norm(b) < std::norm(c)) return -2; // a -> b -> c : line
    return 0;                                  // a -> c -> b : line
}


bool isis_ll(line l, line m) {
    return !eq(cross(l.b - l.a, m.b - m.a), 0);
}

bool isis_ls(line l, segment s) {
    return (cross(l.b - l.a, s.a - l.a) * cross(l.b - l.a, s.b - s.a) < eps);
}

bool isis_lp(line l, point p) {
    return (std::abs(cross(l.b - p, l.a - p)) < eps);
}

bool isis_sp(segment s, point p) {
    return (std::abs(s.a - p) + std::abs(s.b - p) - std::abs(s.b - s.a) < eps);
}

bool isis_ss(segment s, segment t) {
    return ccw(s.a, s.b, t.a) * ccw(s.a, s.b, t.b) <= 0
        && ccw(t.a, t.b, s.a) * ccw(t.a, t.b, s.b) <= 0;
}


point proj(line l, point p) {
    long double t = dot(p - l.a, l.a - l.b) / std::norm(l.a - l.b);
    return l.a + t * (l.a - l.b);
}

point is_ll(line s, line t) {
    point sv = s.b - s.a, tv = t.b - t.a;
    assert(cross(sv, tv) != 0);
    return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}

long double dist_lp(line l, point p) {
    return std::abs(p - proj(l, p));
}

long double dist_ll(line l, line m) {
    return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}

long double dist_ls(line l, segment s) {
    return isis_ls(l, s) ? 0 : std::min(dist_lp(l, s.a), dist_lp(l, s.b));
}

long double dist_sp(segment s, point p) {
    point r = proj(line(s), p);
    return isis_sp(s, r) ? std::abs(r - p) : std::min(std::abs(s.a - p), std::abs(s.b - p));
}

long double dist_ss(segment s, segment t) {
    if(isis_ss(s, t)) return 0;
    long double d1 = std::min(dist_sp(s, t.a), dist_sp(s, t.b));
    long double d2 = std::min(dist_sp(t, s.a), dist_sp(t, s.b));
    return std::min(d1, d2);
}


std::vector<point> is_cc(circle const& c1, circle const& c2) {
    std::vector<point> res;
    long double d = std::abs(c1.p - c2.p);
    long double rc = (d * d + c1.r * c1.r - c2.r * c2.r) / (2 * d);
    long double dfr = c1.r * c1.r - rc * rc;
    if(std::abs(dfr) < eps) {
        dfr = 0.0;
    } else if(dfr < 0.0) {
        return res;
    }

    long double rs = std::sqrt(dfr);
    point diff = (c2.p - c1.p) / d;
    res.push_back(c1.p + diff * point(rc, rs));
    if(dfr != 0.0) {
        res.push_back(c1.p + diff * point(rc, -rs));
    }
    return res;
}

// 0 -> on, 1 -> in, 2 -> out
int is_in_polygon(polygon const& poly, point p) {
    int N = poly.size();
    ld sum = 0;
    for(int i=0; i<N; ++i) {
        point p1 = poly[i], p2 = poly[(i+1)%N];
        if(isis_sp(segment(p1, p2), p)) {
            return 0;
        }
        sum += arg((p2 - p) / (p1 - p));
    }
    return eq(sum, 0) ? 2 : 1;
}

point reflection(line const& l, point p) {
    auto pro = proj(l, p);
    return p + (pro - p) + (pro - p);
}


} // namespace geometry2d

using namespace geometry2d;


constexpr ld INF = 1e18;

ld calc(vector<segment> const& mir, vector<int> const& used, point s, point g) {
    point now = s;
    auto tmpmir = mir;
    // calc goal
    for(int i=0; i<used.size(); ++i) {
        line l = line(tmpmir[used[i]]);
        for(int j=0; j<mir.size(); ++j) {
            tmpmir[j].a = reflection(l, tmpmir[j].a);
            tmpmir[j].b = reflection(l, tmpmir[j].b);
        }
        g = reflection(l, g);
    }

    tmpmir = mir;
    for(int i=0; i<used.size(); ++i) {
        segment path(now, g);
        if(!isis_ss(path, tmpmir[used[i]])) {
            return INF;
        }

        point next = is_ll(line(path), line(tmpmir[used[i]]));
        segment path2(now, next);
        for(int j=0; j<mir.size(); ++j) {
            if(j == used[i] || i != 0 && j == used[i-1]) {
                continue;
            }
            if(isis_ss(path2, tmpmir[j])) {
                return INF;
            }
        }

        line l(tmpmir[used[i]]);
        for(int j=0; j<mir.size(); ++j) {
            tmpmir[j].a = reflection(l, tmpmir[j].a);
            tmpmir[j].b = reflection(l, tmpmir[j].b);
        }
        now = next;
    }

    // last mir -> goal
    int cnt = 0;
    segment last(now, g);
    for(int i=0; i<mir.size(); ++i) {
        if(!used.empty() && i == used.back()) {
            continue;
        }
        cnt += isis_ss(last, tmpmir[i]);
    }

    return (cnt != 0 ? INF : abs(s - g));
}

void solve(vector<segment> const& mir, vector<int>& used, point s, point g, ld& ans) {
    ans = min(ans, calc(mir, used, s, g));
    if(used.size() == 5) {
        return;
    }
    for(int i=0; i<mir.size(); ++i) {
        if(used.empty() || used.back() != i) {
            used.push_back(i);
            solve(mir, used, s, g, ans);
            used.pop_back();
        }
    }
}

int main() {
    int N;
    while(cin >> N, N) {
        vector<segment> mir;
        for(int i=0; i<N; ++i) {
            ld x1, y1, x2, y2;
            cin >> x1 >> y1 >> x2 >> y2;
            mir.emplace_back(point(x1, y1), point(x2, y2));
        }
        point p[2];
        for(int i=0; i<2; ++i) {
            ld x, y;
            cin >> x >> y;
            p[i] = point(x, y);
        }

        ld res = INF;
        vector<int> used;
        solve(mir, used, p[1], p[0], res);
        cout << fixed << setprecision(10) << res << endl;
    }
}

Measured memory_bytes: 3264