#include <iostream>
#include <iomanip>
#include <complex>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;

const double EPS = 1e-10;
const double INF = 1e12;
#define EQ(n,m) (abs((n)-(m)) < EPS)
#define X real()
#define Y imag()

typedef complex<double> P;
typedef vector<P> VP;
struct L : VP{
    L(const P& a, const P& b){ resize(2); at(0)=a; at(1)=b; }
    L(){ resize(2); }
};

namespace std{
	bool operator < (const P &a, const P &b){
		return (a.X!=b.X)? a.X<b.X : a.Y<b.Y;
	}
}

double dot(P a, P b){
    return (conj(a)*b).X;
}
double cross(P a, P b){
    return (conj(a)*b).Y;
}

int ccw(P a, P b, P c){
    b -= a;
    c -= a;
    if(cross(b,c) > EPS) return +1; //ccw
    if(cross(b,c) <-EPS) return -1; //cw
    if(dot(b,c) < EPS) return +2; //c-a-b
    if(norm(b) < norm(c)) return -2; //a-b-c
    return 0; //a-c-b
}
bool intersectSS(const L& s, const L& t){
    return ( ccw(s[0],s[1],t[0]) *ccw(s[0],s[1],t[1]) <= 0 ) &&
        ( ccw(t[0],t[1],s[0]) *ccw(t[0],t[1],s[1]) <= 0 );
}
bool strictItsSS(const L& s, const L& t){
    return ( ccw(s[0],s[1],t[0]) *ccw(s[0],s[1],t[1]) == -1 ) &&
        ( ccw(t[0],t[1],s[0]) *ccw(t[0],t[1],s[1]) == -1);
}

P projection(const L& l, const P& p) {
  double t = dot(p-l[0], l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
P reflection(const L& l, const P& p) {
  return p + 2.0*(projection(l, p) -p);
}
 
P crosspointLL(const L &l, const L &m) {
  double A = cross(l[1]-l[0], m[1]-m[0]);
  double B = cross(l[1]-l[0], l[1]-m[0]);
  return m[0] + B /A *(m[1]-m[0]);
}
bool isParallel(const P &a, const P &b){
    return abs(cross(a,b)) < EPS;
}
bool isParallel(const L &a, const L &b){
    return isParallel(a[1]-a[0], b[1]-b[0]);
}


vector<int> idx(10, -1);
double solve(int step, int end, P s, P g, vector<vector<L> > &wall){
    if(step==end){
    	VP cp(step+2);
    	cp[0]=s; cp[step+1]=g;
        L ray(s,g);
        bool flag = true;
        for(int i=1; i<=step; i++){
            if(!isParallel(ray, wall[i][idx[i]]) && strictItsSS(ray, wall[i][idx[i]])){
                cp[i] = crosspointLL(ray, wall[i][idx[i]]);
            }else{
            	flag = false;
            	break;
            }
        }
        if(flag){
        	for(int i=0; i<=step; i++){
        		if((s<g && cp[i+1]<cp[i]) || (g<s && cp[i]<cp[i+1])){
        			flag = false;
        			break;
        		}
        	}
        }
        
        if(flag){
        	for(int i=0; i<=step; i++){
        		L cut_ray(cp[i], cp[i+1]);
        		for(int j=0; j<(int)wall[0].size(); j++){
        			if(j==idx[i] || j==idx[i+1]) continue;
        			if(intersectSS(cut_ray, wall[i][j])){
        				flag = false;
        				break;
        			}
        		}
        	}
        }
        
        if(flag){
            return abs(g-s);
        }else{
            return INF;
        }
    }
    
    double ans = INF;
    for(int i=0; i<(int)wall[0].size(); i++){
        if(idx[step]==i) continue;
        idx[step+1] = i;
        for(int j=0; j<(int)wall[0].size(); j++){
            wall[step+1][j] = L(reflection(wall[step][i], wall[step][j][0]), reflection(wall[step][i], wall[step][j][1]));
        }
        ans = min(ans, solve(step+1, end, s, reflection(wall[step][i], g), wall));
        idx[step+1] = -1;
    }
    return ans;
}

double search(P s, P g, vector<vector<L> > &wall){
    double ans = INF;
    for(int i=0; i<6; i++){
        ans = min(ans, solve(0,i,s,g,wall));
    }
    return ans;
}

int main(){
    while(1){
        int n;
        cin >> n;
        if(n==0) break;
        
        vector<vector<L> > wall(6, vector<L>(n));
        for(int i=0; i<n; i++){
            for(int j=0; j<2; j++){
                double x,y;
                cin >> x >> y;
                wall[0][i][j] = P(x,y);
            }
        }
        double sx,sy,gx,gy;
        cin >> gx >> gy >> sx >> sy;
        P s(sx,sy), g(gx, gy);

        cout << fixed;
        cout << setprecision(10);
        cout << search(s,g,wall) << endl;
    }
    return 0;
}