#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#pragma comment(linker, "/STACK:400000000")

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define foreach(it,X) for(it=X.begin();it!=X.end();it++)
#define iss istringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sst stringstream
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

typedef complex<double> P;

struct L : public vector<P> {
  L(){}
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
};

double cross(const P& a, const P& b) {
  return imag(conj(a)*b);
}
double dot(const P& a, const P& b) {
  return real(conj(a)*b);
}

int ccw(P a, P b, P c) {
  b -= a; c -= a;
  if (cross(b, c) > 0)   return +1;       // counter clockwise
  if (cross(b, c) < 0)   return -1;       // clockwise
  if (dot(b, c) < 0)     return +2;       // c--a--b on line
  if (norm(b) < norm(c)) return -2;       // a--b--c on line
  return 0;
}

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

P proj(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 refl(const L &l, const P &p) {
  return p + 2.0 * (proj(l, p) - p);
}

P crosspoint(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]);
  if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
  if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
  return m[0] + B / A * (m[1] - m[0]);
}

bool intersectSP(const L &s, const P &p) {
	//cout<<abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0])<<endl;
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}

int n;
double ans;
P s,g;
L M[6];

void f(int time,int pre,int* ref){
	L m[6];
	rep(i,n)m[i]=M[i];
	double res=0;
	P goal=g,point[8];
	rep(i,time){
		goal=refl(m[ref[time-1-i]],goal);
	}
	L laser=L(s,goal);
	point[0]=s;
	L line[7][6];
	rep2(i,1,time+1){
		rep(j,n)line[i-1][j]=m[j];
		if(!intersectSS(laser,m[ref[i-1]]))goto fail;
		point[i]=crosspoint(laser,m[ref[i-1]]);
		for(int j=i-2;j>=0;j--){
			point[i]=refl(line[j][ref[j]],point[i]);
		}
		if(i<time){
			rep(j,n)if(j!=ref[i-1]){
				rep(k,2)m[j][k]=refl(m[ref[i-1]],m[j][k]);
			}
		}
	}
	//rep(i,time)cout<<ref[i]<<" ";cout<<goal<<endl;
	point[time+1]=g;
	//rep(i,time+2)cout<<point[i]<<(i<time+1?"-":"");cout<<endl;
	
	rep(i,time){
		if(intersectSS(L(point[i],point[i+2]),M[ref[i]]))goto fail;
	}
	
	rep(i,time+1){
		rep(j,n){
			if(i>0&&j==ref[i-1]||i<time&&j==ref[i]){
				//cout<<i<<" "<<j<<"cont"<<intersectSS(L(point[i],point[i+1]),m[j])<<endl;
				//cout<<point[i]<<"-"<<point[i+1]<<" "<<m[j][0]<<" "<<m[j][1]<<endl;
				//cout<<intersectSP(m[j],point[1])<<endl;
				continue;
			}
			if(intersectSS(L(point[i],point[i+1]),M[j]))goto fail;
		}
	}
	
	//cout<<"OK ";
	rep(i,time+1)res+=abs(point[i+1]-point[i]);//,cout<<point[i+1]-point[i]<<" "<<abs(point[i+1]-point[i])<<" ";
	//cout<<res<<endl;
	ans=min(ans,res);
	fail:;
	if(time<5){
		rep(i,n)if(i!=pre){
			*(ref+time)=i;
			f(time+1,i,ref);
		}
	}
}

int main(){
	//cout<<intersectSS(L(P(24,64),P(-40,0)),L(P(0,10),P(-12,30)))<<endl;
	//cout<<crosspoint(L(P(24,64),P(-40,0)),L(P(0,10),P(-12,30)))<<endl;
	//cout<<crosspoint(L(P(72,77),P(7,10)),L(P(55.2192,0),P(55.2192,100)))<<endl;
	while(cin>>n && n){
		rep(i,n){
			double x,y,xx,yy;
			cin>>x>>y>>xx>>yy;
			M[i]=L(P(x,y),P(xx,yy));
		}
		double tx,ty,lx,ly;
		cin>>tx>>ty>>lx>>ly;
		s=P(lx,ly),g=P(tx,ty);
		ans=INF;
		int ref[6];
		f(0,-1,ref);
		cout<<setprecision(15)<<ans<<endl;
	}
}