#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const double EPS = 1e-8;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}
double dLP(Pt a, Pt b, Pt c) {
	return ABS(tri(a, b, c)) / (b - a).ABS();
}
bool iSS(Pt a, Pt b, Pt c, Pt d) {
	return (sig(tri(a, b, c)) * sig(tri(a, b, d)) < 0 && sig(tri(c, d, a)) * sig(tri(c, d, b)) < 0);
}
Pt pLL(Pt a, Pt b, Pt c, Pt d) {
	b = b - a; d = d - c; return a + b * (c - a).det(d) / b.det(d);
}

Pt p[10];
Pt q[10];
Pt s;
Pt t;
double ret=0;
int use[10];
int n;
Pt u[10][10];
Pt v[10][10];
void move(int a){
	for(int i=0;i<n;i++){
		if(i==a)continue;
		double dis=dLP(p[a],q[a],p[i])*2;
		Pt vec;
		if(iSP(p[a],q[a],p[i])==-1){
			vec=((q[a]-p[a])*Pt(0,1));
		}else{
			vec=((p[a]-q[a])*Pt(0,1));
		}
		vec=vec/vec.ABS();
		p[i]=p[i]+vec*dis;
		dis=dLP(p[a],q[a],q[i])*2;
		if(iSP(p[a],q[a],q[i])==-1){
			vec=((q[a]-p[a])*Pt(0,1));
		}else{
			vec=((p[a]-q[a])*Pt(0,1));
		}
		vec=vec/vec.ABS();
		q[i]=q[i]+vec*dis;
	//	printf("%d: (%f, %f) (%f, %f)\n",i,p[i].x,p[i].y,q[i].x,q[i].y);
	}
	double dis=dLP(p[a],q[a],t)*2;
	Pt vec;
	if(iSP(p[a],q[a],t)==-1){
		vec=((q[a]-p[a])*Pt(0,1));
	}else{
		vec=((p[a]-q[a])*Pt(0,1));
	}
	vec=vec/vec.ABS();
	t=t+vec*dis;
	//printf("t: (%f, %f)\n",t.x,t.y);
}

void solve(int a,int b){
	bool ok=true;
	Pt at=s;
	for(int i=0;i<a;i++){
		Pt val=t;
		int nat=-1;
		for(int j=0;j<n;j++){
			if((i==0||use[i-1]!=j)&&iSS(at,val,u[i][j],v[i][j])){
				nat=j;
				val=pLL(at,val,u[i][j],v[i][j]);
			}
		}
		if(nat!=use[i]){ok=false;break;}
		at=val;
	}
	for(int j=0;j<n;j++){
		if(iSS(at,t,u[a][j],v[a][j]))ok=false;
	}
	if(ok){
		ret=min(ret,(t-s).ABS());
	}
	if(a<6){
		for(int i=0;i<n;i++){
			if(b==i)continue;
			use[a]=i;
			move(i);
			for(int j=0;j<n;j++){
				u[a+1][j]=p[j];
				v[a+1][j]=q[j];
			}
			solve(a+1,i);
			move(i);
		}
	}
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		n=a;
		for(int i=0;i<a;i++){
			double X1,X2,Y1,Y2;
			scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2);
			p[i]=Pt(X1,Y1);
			q[i]=Pt(X2,Y2);
		}
		double ix,iy;scanf("%lf%lf",&ix,&iy);
		for(int i=0;i<a;i++){
			u[0][i]=p[i];
			v[0][i]=q[i];
		}
		t=Pt(ix,iy);
		scanf("%lf%lf",&ix,&iy);
		s=Pt(ix,iy);
		ret=999999999;
		solve(0,-1);
		printf("%.12f\n",ret);
	}
}

Measured memory_bytes: 1096