#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>

#define REP(i,n) for(i=0; i < (n); i++)
#define REPONE(i, n) for(i=1; i <= (n); i++)
#define LOOP(n) for(int loopCount=1; loopCount <= (n); loopCount++)
#define ITER(c) __typeof((c).begin())
#define EACH(c,it) for(ITER(c) it =(c).begin(); it!=(c).end(); it++)
#define SZ(c) ((int) (c).size())
#define ALL(c) c.begin(), c.end()
#define SUM(c) accumulate(ALL(c), 0)
#define EXIST(c,v) (find(ALL(c), (v)) != (c).end())
#define PB push_back
#define MP make_pair
#define INF (1e99)

using namespace std;
static const double PI = 3.141592653589793238462643383279;
typedef long long ll;

#define P complex<T> 
#define EPS (1e-12)

//XJ[lÌðÔ·B+:1, -:-1, 0:0B
template<typename T>
int sig(T a){
    return a==0?0:a>0?1:-1;
}

//xNgp1, p2ÌàÏðÔ·
template<typename T>
T iprod(P p1, P p2){
    return (p1.real()*p2.real()) + (p1.imag()*p2.imag());
}

//xNgp1, p2ÌOÏ(XJ[l,zÀW)ðÔ·
template<typename T>
T oprod(P p1, P p2){
    return (p1.real()*p2.imag()) - (p1.imag()*p2.real());
}


//üª(p1, p2)Æ_qÌ£ðÔ·
template<typename T>
T disSP(P p1, P p2, P q){
    if(iprod( (p2-p1), (q-p1) ) < EPS) return abs(q-p1);
    if(iprod( (p1-p2), (q-p2) ) < EPS) return abs(q-p2);
    return disLP(p1, p2, q);
}

//¼ü(p1, p2)Æ_qÌ£ðÔ·
template<typename T>
T disLP(P p1, P p2, P q){
    return abs( oprod( (p2-p1), (q-p1) ) ) / abs(p2-p1);
}

//üª(p1, p2)Æüª(q1, q2)Ìð_ª¶Ý·éÆ«ÉtrueðÔ·
template<typename T>
bool crsSS(P p1, P p2, P q1, P q2){
    if(disSP(p1,p2,q1)<EPS || disSP(p1,p2,q2)<EPS || disSP(q1,q2,p1)<EPS || disSP(q1,q2,p2)<EPS) return true;
    if(max(p1.real(), p2.real()) + EPS < min(q1.real(), q2.real())) return false;
    if(max(q1.real(), q2.real()) + EPS < min(p1.real(), p2.real())) return false;
    if(max(p1.imag(), p2.imag()) + EPS < min(q1.imag(), q2.imag())) return false;
    if(max(q1.imag(), q2.imag()) + EPS < min(p1.imag(), p2.imag())) return false;
   return sig(oprod(p2-p1, q1-p1)) * sig(oprod(p2-p1, q2-p1)) < EPS
        && sig(oprod(q2-q1, p1-q1)) * sig(oprod(q2-q1, p2-q1)) < EPS;
}


//_q©ç¼ü(p1, p2)Éºëµ½üÌ«ðÔ·
template<typename T>
P proj(P p1, P p2, P q){
    return p1 + (iprod( p2-p1, q-p1 )/(norm(p2-p1))*(p2-p1));
}

//¼ü(p1,p2)Æ¼ü(q1, q2)Ìð_ðÔ·
template<typename T>
P isLL(P p1, P p2, P q1, P q2){
    T d = oprod( q2-q1, p2-p1 );
    if ( abs(d) < EPS ) return NULL;
    return p1 + (oprod(q2-q1, q1-p1)/d*(p2-p1));
}


//¼ü(p1,p2)ÉÖµÄ_qÆÎÛÈ_ðÔ·
template<typename T>
P mirrorLP(P p1, P p2, P q){
    return (T)2*proj(p1,p2,q) - q;
}

//¼ü(p1,p2)ÉÖµÄüª(q1, q2)ÆÎÛÈüªðÔ·
template<typename T>
vector<P> mirrorLS(P p1, P p2, P q1, P q2){
    P r1=mirrorLP(p1, p2, q1);
    P r2=mirrorLP(p1, p2, q2);
    vector<P> ans;
    ans.PB(r1);
    ans.PB(r2);
    return ans;
}

typedef complex<long double> cd;

int main(){
    int i, j, n, x, y, z, w, m;
    while(cin>>n){
        if(n==0) break;

        //input read
        vector< vector<cd> > mirrors;
        vector<cd> hoge;
        cd start, goal;
        LOOP(n){
            cin >> x >> y >> z >> w;
            hoge.clear();
            hoge.PB(cd(x,y));
            hoge.PB(cd(z,w));
            mirrors.PB(hoge);
        }
        cin >> x >> y;
        goal = cd(x,y);
        cin >> x >> y;
        start  = cd(x,y);

        //generate pattern
        set< vector<int> > pats;
        vector<int> pat;
        int i1, i2, i3, i4, i5;
        REP(i1,n+1)REP(i2,n+1)REP(i3,n+1)REP(i4,n+1)REP(i5,n+1){
            pat.clear();
            if(i1<n) pat.PB(i1);
            if(i2<n) pat.PB(i2);
            if(i3<n) pat.PB(i3);
            if(i4<n) pat.PB(i4);
            if(i5<n) pat.PB(i5);
            if(SZ(pat)>1){
                REP(i,SZ(pat)-1)if(pat[i]==pat[i+1]) goto esc;
            }
            pats.insert(pat);
esc:;
        }
//        EACH(pats,it){EACH(*it, itt) cout << *itt <<","; cout << endl;}

        //solve
        double ans = INF;
        EACH(pats,it){
            pat = *it;
            m = SZ(pat);
            vector< vector< vector<cd> > > ms;
            vector< vector<cd> > tmp;
            vector<cd> tmp2, tmp3;
            ms.PB(mirrors);
            cd mg=goal;
            REP(i,m){
                tmp = ms.back();
                tmp3 = tmp[pat[i]];
                REP(j,n)if(j!=pat[i]){
                    tmp2 = mirrorLS(tmp3[0], tmp3[1], tmp[j][0], tmp[j][1]);
                    tmp[j] = tmp2;
                }
                mg = mirrorLP(tmp3[0], tmp3[1], mg);
                ms.PB(tmp);
            }

            //debug
/*            REP(i,m+1){
                REP(j,n){
                    cout << ms[i][j][0] <<":"<< ms[i][j][1] << endl;
                }
                cout << endl;
            }
            cout << mg << endl;
            cout << abs(start - mg) << endl;
            cout << disSP(ms[1][0][0], ms[1][0][1], ms[1][4][0]) << endl;
            */

            if(abs(start-mg) < ans){
                cd prev=start, next;
                vector< vector<cd> > segs;
                REP(i,m){
                    next = isLL(start, mg, ms[i][pat[i]][0], ms[i][pat[i]][1]);
                    tmp2.clear();
                    tmp2.PB(prev);
                    tmp2.PB(next);
                    segs.PB(tmp2);
                    prev = next;
                }
                tmp2.clear();
                tmp2.PB(prev);
                tmp2.PB(mg);
                segs.PB(tmp2);

                REP(i,m){
                    if(iprod(segs[i][0]-segs[i][1], segs[i+1][0]-segs[i+1][1])<0) goto end;
                }

                //ð·»è
                if(m==0){
                    REP(j,n)if(crsSS(mirrors[j][0], mirrors[j][1], start, goal)) goto end;
                }
                else if(m>0){
                REP(j,n){
                    if(j != pat[0] && crsSS(segs[0][0], segs[0][1], ms[0][j][0], ms[0][j][1]))
                        goto end;
                    if(j == pat[0] && !crsSS(start, mg, ms[0][j][0], ms[0][j][1]))
                        goto end;
                }
                REPONE(i,m-1){
                    REP(j,n){
                        if( (j!=pat[i-1] && j!=pat[i]) && crsSS(segs[i][0], segs[i][1], ms[i][j][0], ms[i][j][1]))
                            goto end;
                        if( (j==pat[i-1] || j==pat[i]) && !crsSS(start, mg, ms[i][j][0], ms[i][j][1]))
                            goto end;
                    }
                }
                REP(j,n){
                    if(j != pat.back() && crsSS(segs[m][0], segs[m][1], ms[m][j][0], ms[m][j][1]))
                        goto end;
                    if(j == pat.back() && !crsSS(start, mg, ms[m][j][0], ms[m][j][1]))
                        goto end;
                }
                }

                ans = abs(start-mg);
//                EACH(pat,ittt)cout<<*ittt<<",";cout<<endl;
            }
end:;
        }
        printf("%.10f\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1080