#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




struct Point{
	Point(double arg_x,double arg_y){
		x = arg_x;
		y = arg_y;
	}

	Point(){
		x = y = 0.0;
	}

	Point operator + (Point p){ return Point(x+p.x,y+p.y); }
	Point operator - (Point p){ return Point(x-p.x,y-p.y);}
	Point operator * (double a){ return Point(a*x,a*y); }
	Point operator / (double a){ return Point(x/a,y/a); }

	double abs(){ return sqrt(norm()); }
	double norm(){ return x*x + y*y; }

	bool operator<(const Point &p) const{
		return x != p.x? x < p.x: y < p.y;
	}

	bool operator == (const Point &p) const{
		return fabs(x-p.x) < EPS && fabs(y-p.y) < EPS;
	}

	double x,y;
};

typedef Point Vector;

struct Line{
	Line(){

	}
	Line(Point a,Point b){
		p[0] = a;
		p[1] = b;
	}
	Point p[2];
};

int N;
double ans;
Line line[5];
Point start,goal;

int func(double x1,double y1,double x2, double y2, double xp, double yp){
	double naiseki,norm1,norm2,gaiseki;
	norm1 = sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));
	norm2 = sqrt((xp-x1)*(xp-x1)+(yp-y1)*(yp-y1));
	naiseki = (xp-x1)*(x2-x1)+(yp-y1)*(y2-y1);
	gaiseki = (x2-x1)*(yp-y1)-(xp-x1)*(y2-y1);
	if(gaiseki > EPS){
		return 1;
	}else if(gaiseki < -EPS){
		return -1;
	}
	if(naiseki < -EPS){
		return 2;
	}

	if(norm1 < norm2){
		return -2;
	}
	return 0;
}


//★★直線ではなく、線分の交差判定★★
bool is_Cross(Line a,Line b){

	if(func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[0].x,b.p[0].y)*
			func(a.p[0].x,a.p[0].y,a.p[1].x,a.p[1].y,b.p[1].x,b.p[1].y) <= 0 &&
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[0].x,a.p[0].y)*
			func(b.p[0].x,b.p[0].y,b.p[1].x,b.p[1].y,a.p[1].x,a.p[1].y) <= 0){
		return true;
	}
	return false;
}

//交点を求める関数
Point calc_Cross_Point(double x1,double x2,double x3,double x4,double y1,double y2,double y3,double y4){
	Point ret;
	ret.x = ((x2-x1)*(y3*(x4-x3)+x3*(y3-y4))-(x4-x3)*(y1*(x2-x1)+x1*(y1-y2)))/((y2-y1)*(x4-x3)-(y4-y3)*(x2-x1));
	if(x1 != x2){
		ret.y = ((y2-y1)*ret.x+y1*(x2-x1)+x1*(y1-y2))/(x2-x1);
	}else{
		ret.y = ((y4-y3)*ret.x+y3*(x4-x3)+x3*(y3-y4))/(x4-x3);
	}
	return ret;
}


Point calc_minus(Point a,Point b){
    Point ret;

    ret.x = a.x-b.x;
    ret.y = a.y-b.y;

    return ret;
}

double calc_len(Vector a){
    return sqrt(a.x*a.x+a.y*a.y);
}

double cross(Vector a,Vector b){
    return a.x*b.y-a.y*b.x;
}

double dot(Vector a,Vector b){
    return a.x*b.x + a.y*b.y;
}


//線分ではなく直線と点の距離
double getDistanceLP(Line l,Point p){
    return fabs(cross(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0]))/calc_len(calc_minus(l.p[1],l.p[0])));
}

//点と線分の距離
double getDistanceSP(Line l,Point p){
	if(dot(calc_minus(l.p[1],l.p[0]),calc_minus(p,l.p[0])) < 0.0)return calc_len(calc_minus(p,l.p[0]));
	if(dot(calc_minus(l.p[0],l.p[1]),calc_minus(p,l.p[1])) < 0.0)return calc_len(calc_minus(p,l.p[1]));
	return getDistanceLP(l,p);
}

//線分と線分の距離
double getDistance(Line A,Line B){
	if(is_Cross(A,B))return 0.0;
	return min(min(getDistanceSP(A,B.p[0]),getDistanceSP(A,B.p[1])),
			min(getDistanceSP(B,A.p[0]),getDistanceSP(B,A.p[1])));
}


//インタフェース関数
Point calc_Cross_Point(Point a,Point b,Point c,Point d){
	return calc_Cross_Point(a.x,b.x,c.x,d.x,a.y,b.y,c.y,d.y);
}

Point calc_Cross_Point(Line A,Line B){

	if(getDistanceSP(B,A.p[0]) < EPS){

		return A.p[0];

	}else if(getDistanceSP(B,A.p[1]) < EPS){

		return A.p[1];

	}else if(getDistanceSP(A,B.p[0]) < EPS){

		return B.p[0];

	}else if(getDistanceSP(A,B.p[1]) < EPS){

		return B.p[1];
	}

	return calc_Cross_Point(A.p[0],A.p[1],B.p[0],B.p[1]);
}

Point calc_Reflection_Point(double x1,double y1,double x2,double y2,double xp,double yp){

	Point ret;

	bool X_FLG = false,Y_FLG = false;
	double slope;

	if(y1 == y2){
		X_FLG = true;
	}else if(x1 == x2){
		Y_FLG = true;
	}else{
		slope = (y2-y1)/(x2-x1);
	}

	if(X_FLG){
		ret.x = xp,ret.y=y1;
	}else if(Y_FLG){
		ret.x = x1,ret.y = yp;
	}else{
		ret.x = (yp*(x2-x1)*(y2-y1)+xp*(x2-x1)*(x2-x1)-y1*(y2-y1)*(x2-x1)+x1*(y2-y1)*(y2-y1))/((y2-y1)*(y2-y1)+(x2-x1)*(x2-x1));
		ret.y = ((x1-x2)*ret.x+yp*(y2-y1)+xp*(x2-x1))/(y2-y1);
	}
	ret.x = 2*ret.x-xp;
	ret.y = 2*ret.y-yp;

	return ret;
}

Point calc_Reflection_Point(Line line,Point point){

	return calc_Reflection_Point(line.p[0].x,line.p[0].y,line.p[1].x,line.p[1].y,point.x,point.y);
}

double calc_dist(Point A,Point B){

	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}


void calc(vector<int> V){

	Point GOAL = goal;
	Line work[5];
	for(int i = 0; i < N; i++){

		work[i] = line[i];
	}

	//goalの最終位置を計算
	for(int i = 0; i < V.size(); i++){
		for(int k = 0; k < N; k++){
			if(k == V[i])continue;
			work[k].p[0] = calc_Reflection_Point(work[V[i]],work[k].p[0]);
			work[k].p[1] = calc_Reflection_Point(work[V[i]],work[k].p[1]);
		}

		GOAL = calc_Reflection_Point(work[V[i]],GOAL);
	}

	for(int i = 0; i < N; i++){

		work[i] = line[i];
	}

	int last;
	double sum = 0;

	Point from = start;

	for(int i = 0; i < V.size(); i++){

		last = V[i];
		Line tmp_line = Line(from,GOAL);

		if(!is_Cross(tmp_line,work[V[i]])){
			return;
		}

		Point cross_point = calc_Cross_Point(tmp_line,work[V[i]]);

		tmp_line.p[0] = from;
		tmp_line.p[1] = cross_point;

		for(int k = 0; k < N; k++){ //使わない鏡も見る
			if(k == V[i] || (i > 0 && k == V[i-1]))continue;
			if(is_Cross(tmp_line,work[k])){
				return;
			}
		}

		sum += calc_dist(from,cross_point);

		for(int k = 0; k < N; k++){
			if(k == V[i])continue;
			work[k].p[0] = calc_Reflection_Point(work[V[i]],work[k].p[0]);
			work[k].p[1] = calc_Reflection_Point(work[V[i]],work[k].p[1]);
		}

		from = cross_point;
	}

	Line final = Line(from,GOAL);

	for(int k = 0; k < N; k++){
		if(k == last)continue;
		if(is_Cross(final,work[k])){
			return;
		}
	}

	sum += calc_dist(from,GOAL);

	ans = min(ans,sum);
}


void func(){

	for(int i = 0; i < N; i++){

		scanf("%lf %lf %lf %lf",&line[i].p[0].x,&line[i].p[0].y,&line[i].p[1].x,&line[i].p[1].y);
	}
	scanf("%lf %lf",&goal.x,&goal.y);
	scanf("%lf %lf",&start.x,&start.y);

	ans = BIG_NUM;
	vector<int> V;

	//0
	calc(V);

	vector<int> A,B,C,D,E;

	for(int a = 0; a < N; a++){
		A.clear();
		A.push_back(a);
		calc(A);
		for(int b = 0; b < N; b++){
			if(b == a)continue;
			B.clear();
			B.push_back(a);
			B.push_back(b);
			calc(B);
			for(int c = 0; c < N; c++){
				if(c == b)continue;
				C.clear();
				C.push_back(a);
				C.push_back(b);
				C.push_back(c);
				calc(C);
				for(int d = 0; d < N; d++){
					if(d == c)continue;
					D.clear();
					D.push_back(a);
					D.push_back(b);
					D.push_back(c);
					D.push_back(d);
					calc(D);
					for(int e = 0; e < N; e++){
						if(e == d)continue;
						E.clear();
						E.push_back(a);
						E.push_back(b);
						E.push_back(c);
						E.push_back(d);
						E.push_back(e);
						calc(E);
					}
				}
			}
		}
	}

	printf("%.10lf\n",ans);
}

int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



Measured memory_bytes: 3264