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

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;

const int INF=1e9;
const int MOD=1e9+7;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int Signum(double x){
	return x<-EPS?-1:x>EPS?1:0;
}

struct Point{
	double x,y;
	Point(){}
	Point(double x,double y):x(x),y(y){}
	Point& operator+=(Point p){x+=p.x,y+=p.y; return *this;}
	Point& operator-=(Point p){x-=p.x,y-=p.y; return *this;}
	Point& operator*=(double c){x*=c,y*=c; return *this;}
	Point& operator/=(double c){x/=c,y/=c; return *this;}
};
Point operator+(Point a,Point b){return a+=b;}
Point operator-(Point a,Point b){return a-=b;}
Point operator*(Point a,double c){return a*=c;}
Point operator*(double c,Point a){return a*=c;}
Point operator/(Point a,double c){return a/=c;}
bool operator==(Point a,Point b){return abs(a.x-b.x)<EPS && abs(a.y-b.y)<EPS;}
bool operator!=(Point a,Point b){return !(a==b);}

double Abs(Point p){
	return sqrt(p.x*p.x+p.y*p.y);
}
double Abs2(Point p){
	return p.x*p.x+p.y*p.y;
}
double Arg(Point p){
	return atan2(p.y,p.x);
}
double Dot(Point a,Point b){
	return a.x*b.x+a.y*b.y;
}
double Cross(Point a,Point b){
	return a.x*b.y-a.y*b.x;
}
Point Rot(Point p,double t){
	return Point(cos(t)*p.x-sin(t)*p.y,sin(t)*p.x+cos(t)*p.y);
}

struct Line{
	Point pos,dir;
	Line(){}
	Line(Point p,Point d):pos(p),dir(d){}
	Line(double x,double y,double u,double v):pos(x,y),dir(u,v){}
};

Point Proj(Line l,Point p){
	Point a=p-l.pos,b=l.dir;
	return l.pos+Dot(a,b)/Abs2(b)*b;
}
Point Refl(Line l,Point p){
	return 2*Proj(l,p)-p;
}

struct Segment{
	Point pos,dir;
	Segment(){}
	Segment(Point p,Point d):pos(p),dir(d){}
	Segment(double x,double y,double u,double v):pos(x,y),dir(u,v){}
	explicit Segment(Line l):pos(l.pos),dir(l.dir){}
	explicit operator Line()const{return Line(pos,dir);}
};

int CCW(Point a,Point b,Point c){
	b-=a,c-=a;
	if(int sign=Signum(Cross(b,c)))
		return sign; // 1:ccw,-1:cw
	if(Dot(b,c)<-EPS)
		return -2;   // c-a-b
	if(Abs2(b)<Abs2(c)-EPS)
		return 2;    // a-b-c
	return 0;        // a-c-b (inclusive)
}

ostream& operator<<(ostream& os,const Point& p){
	return os<<'('<<p.x<<','<<p.y<<')';
}
ostream& operator<<(ostream& os,const Line& l){
	return os<<'('<<l.pos<<','<<l.dir<<')';
}
ostream& operator<<(ostream& os,const Segment& s){
	return os<<'('<<s.pos<<','<<s.dir<<')';
}

bool IntersectLS(Line l,Segment s){
	Point a=s.pos-l.pos,b=s.pos+s.dir-l.pos;
	return Signum(Cross(l.dir,a))*Signum(Cross(l.dir,b))<=0;
}
bool IntersectSS(Segment a,Segment b){
	int c1=CCW(a.pos,a.pos+a.dir,b.pos),c2=CCW(a.pos,a.pos+a.dir,b.pos+b.dir);
	int c3=CCW(b.pos,b.pos+b.dir,a.pos),c4=CCW(b.pos,b.pos+b.dir,a.pos+a.dir);
	return c1*c2<=0 && c3*c4<=0;
}
bool IntersectSP(Segment s,Point p){
	return CCW(s.pos,s.pos+s.dir,p)==0;
}

Point InterPointLL(Line a,Line b){
	if(abs(Cross(a.dir,b.dir))<EPS) return a.pos;
	return a.pos+Cross(b.pos-a.pos,b.dir)/Cross(a.dir,b.dir)*a.dir;
}
Point InterPointSS(Segment a,Segment b){
	if(abs(Cross(a.dir,b.dir))<EPS){
		if(IntersectSP(b,a.pos)) return a.pos;
		if(IntersectSP(b,a.pos+a.dir)) return a.pos+a.dir;
		if(IntersectSP(a,b.pos)) return b.pos;
		if(IntersectSP(a,b.pos+b.dir)) return b.pos+b.dir;
	}
	return InterPointLL(Line(a),Line(b));
}

double calc(Point laser,Point target,vector<Segment> mirrors,vi order)
{
	int n=mirrors.size();
	
	auto backup=mirrors;
	for(int i:order){
		//puts(">");
		//for(auto m:mirrors)
		//	printf("(%.1f %.1f %.1f %.1f)\n",m.pos.x,m.pos.y,m.pos.x+m.dir.x,m.pos.y+m.dir.y);
		//printf("(%.1f %.1f)\n",target.x,target.y);
		
		target=Refl(Line(mirrors[i]),target);
		rep(j,n) if(j!=i){
			Point a=mirrors[j].pos,b=a+mirrors[j].dir;
			a=Refl(Line(mirrors[i]),a);
			b=Refl(Line(mirrors[i]),b);
			mirrors[j]=Segment(a,b-a);
		}
	}
	Segment beam(laser,target-laser);
	mirrors=backup;
	
	bool ok=true;
	for(int i:order){
		if(!IntersectSS(beam,mirrors[i])) return INF;
		
		vd dists(n,INF);
		rep(j,n) if(IntersectSS(beam,mirrors[j]))
			dists[j]=Abs(InterPointSS(beam,mirrors[j])-beam.pos);
		
		rep(j,n){
			if(dists[j]<EPS) continue;
			if(dists[j]<dists[i]-EPS) return INF;
		}
		Point d=InterPointSS(beam,mirrors[i]);
		if(Dot(d-beam.pos,beam.dir)<-EPS) return INF;
		beam.pos=d;
		
		rep(j,n) if(j!=i){
			Point a=mirrors[j].pos,b=a+mirrors[j].dir;
			a=Refl(Line(mirrors[i]),a);
			b=Refl(Line(mirrors[i]),b);
			mirrors[j]=Segment(a,b-a);
		}
	}
	{
		vd dists(n,INF);
		rep(j,n) if(IntersectSS(beam,mirrors[j]))
			dists[j]=Abs(InterPointSS(beam,mirrors[j])-beam.pos);
		rep(j,n){
			if(dists[j]<EPS) continue;
			if(dists[j]<Abs(target-beam.pos)-EPS) return INF;
		}
		if(Dot(target-beam.pos,beam.dir)<-EPS) return INF;
	}
	
	return ok?Abs(target-laser):INF;
}

double solve(Point laser,Point target,vector<Segment> mirrors,vi order)
{
	double res=calc(laser,target,mirrors,order);
	if(order.size()<5){
		rep(i,mirrors.size()) if(order.empty() || i!=order.back()){
			order.push_back(i);
			res=min(res,solve(laser,target,mirrors,order));
			order.pop_back();
		}
	}
	return res;
}

int main()
{
	for(int n;cin>>n && n;){
		vector<Segment> mirrors;
		rep(i,n){
			int x1,y1,x2,y2; cin>>x1>>y1>>x2>>y2;
			mirrors.emplace_back(x1,y1,x2-x1,y2-y1);
		}
		Point target,laser;
		cin>>target.x>>target.y>>laser.x>>laser.y;
		
		printf("%.14f\n",solve(laser,target,mirrors,vi()));
		//dump(calc(laser,target,mirrors,vi({1,2,4})));
		//dump(calc(laser,target,mirrors,vi({2,1})));
	}
}

Measured memory_bytes: 1264