#include <iostream>
#include <cmath>
#include <cstring>
#include <vector>
#define EPS 1e-9
#define INF 1e10

using namespace std;

class L;

class P{
public:
	double x,y;
	P(){x=0;y=0;}
	P(double x, double y){this->x=x;this->y=y;}
	P reflect(L l);
	void print(){
		printf("P(%.1lf,%.1lf)\n", x, y);
	}
};
class L{
public:
	P p1,p2;
	L(){}
	L(P p1, P p2){this->p1=p1;this->p2=p2;}
	L reflect(L l);
	void print(){
		printf("L(P(%.1lf,%.1lf)->P(%.1lf,%.1lf))\n", p1.x, p1.y, p2.x, p2.y);
	}
};

P P::reflect(L l){
	double dx = (l.p2.x - l.p1.x), dy = (l.p2.y - l.p1.y);
	double a = dx * dx + dy *dy, b = dx * (l.p1.x - x) + dy * (l.p1.y - y);
	double t = -b / a;
	double tx = l.p1.x + dx * t, ty = l.p1.y + dy * t;
//	printf("reflect t=(%lf,%lf)\n", tx,ty);
	
	this->x = 2*tx-x;
	this->y = 2*ty-y;
	return *this;
}
L L::reflect(L l){
	this->p1.reflect(l);
	this->p2.reflect(l);
	return *this;
}


int isIntersect(L l1, L l2){
//printf("isintersect(%.0lf, %.0lf)(%.0lf, %.0lf), (%.0lf,%.0lf)(%.0lf,%.0lf)\n", l1.p1.x, l1.p1.y, l1.p2.x, l1.p2.y, l2.p1.x, l2.p1.y, l2.p2.x, l2.p2.y);
	if (((l1.p1.x - l1.p2.x) * (l2.p1.y - l1.p1.y) + (l1.p1.y - l1.p2.y) * (l1.p1.x - l2.p1.x)) * 
		((l1.p1.x - l1.p2.x) * (l2.p2.y - l1.p1.y) + (l1.p1.y - l1.p2.y) * (l1.p1.x - l2.p2.x)) < 0){
		if (((l2.p1.x - l2.p2.x) * (l1.p1.y - l2.p1.y) + (l2.p1.y - l2.p2.y) * (l2.p1.x - l1.p1.x)) * 
			((l2.p1.x - l2.p2.x) * (l1.p2.y - l2.p1.y) + (l2.p1.y - l2.p2.y) * (l2.p1.x - l1.p2.x)) < 0	){
			return 1;
		}
	}
	return 0;
}

P getIntersect(L l1, L l2){
//	double S1 = ((l2.p2.x - l1.p2.x) * (l1.p1.y - l1.p2.y) - (l2.p2.y - l1.p2.y) * (l1.p1.x - l1.p2.x)) / 2;
//	double S2 = ((l2.p2.x - l1.p2.x) * (l1.p2.y - l2.p1.y) - (l2.p2.y - l1.p2.y) * (l1.p2.x - l2.p1.x)) / 2;
//	printf("%lf, %lf\n", S1,S2);
//	return P(l1.p1.x + (l2.p1.x - l1.p1.x) * S1 / (S1 + S2 + EPS), l1.p1.y + (l2.p1.y - l1.p1.y) * S1 / (S1 + S2 + EPS));

	double S1 = ((l2.p2.x - l2.p1.x) * (l1.p1.y - l2.p1.y) - (l2.p2.y - l2.p1.y) * (l1.p1.x - l2.p1.x)) / 2;
	double S2 = ((l2.p2.x - l2.p1.x) * (l2.p1.y - l1.p2.y) - (l2.p2.y - l2.p1.y) * (l2.p1.x - l1.p2.x)) / 2;
	return P(l1.p1.x + (l1.p2.x - l1.p1.x) * S1 / (S1 + S2 + EPS), l1.p1.y + (l1.p2.y - l1.p1.y) * S1 / (S1 + S2 + EPS));
}


L mir[6][6];
P start, tgoal;
int n;
double ans;
void check(vector <int> ref){
	int i,j;
	P goal = tgoal;
//	cout << "check " << ref.size() << endl;
//	goal.print();
	for(i=0;i<int(ref.size());i++){
		for(j=0;j<n;j++){
			mir[i+1][j] = mir[i][j];
			if(ref[i]!=j) mir[i+1][j].reflect(mir[i][ref[i]]);
		}
//		mir[i][ref[i]].print();
		goal.reflect(mir[i][ref[i]]);
//		goal.print();
	}
	P cur = start;
	P is;
	for(i=0;i<=int(ref.size());i++){
		L laser = L(cur, goal);
		if(i != int(ref.size())){
			if(!isIntersect(laser, mir[i][ref[i]])){
//				printf("not intersect %d, %d\n", i, ref[i]);
				return;
			}
			is = getIntersect(laser, mir[i][ref[i]]);
		}else is = goal;
		laser.p2 = is;
		for(j=0;j<n;j++){
			if((i == int(ref.size()) || ref[i]!= j) &&
			   (!i || ref[i-1]!= j) &&
			    isIntersect(laser, mir[i][j])){
//				printf("intersect %d, %d\n", i, j);
//				laser.print();
//				mir[i][j].print();
				return;
			}
		}
		
		cur = is;
	}
//	cout << "success " << sqrt	((goal.x-start.x)*(goal.x-start.x)+(goal.y-start.y)*(goal.y-start.y)) << endl;
	ans = min(ans, (goal.x-start.x)*(goal.x-start.x)+(goal.y-start.y)*(goal.y-start.y));
}

void solve(vector<int> ref){
	int i;

	check(ref);
	if(ref.size()<5){
		for(i=0;i<n;i++){
			if(ref.size() && ref[ref.size()-1] == i) continue;
			ref.push_back(i);
			solve(ref);
			ref.pop_back();
		}
	}
}

int main(){
	int i,x1,y1,x2,y2;
	vector<int> ref;

//	getIntersect( L(P(0,0),P(1,1)), L(P(1,0),P(0,1)) ).print();
//	P(0,100).reflect(L(P(60,30),P(60,95))).print();
//	return 0;

	while(cin>>n,n){
		ans = 1e9;
		for(i=0;i<n;i++){
			cin>>x1>>y1>>x2>>y2;
			mir[0][i] = L(P(x1,y1),P(x2,y2));
		}
		cin>>tgoal.x>>tgoal.y>>start.x>>start.y;
		
		ref.clear();
		solve(ref);
		cout << sqrt(ans) << endl;
	}
}