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

const double EPS = 1e-9;
typedef complex<double> P;


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

double dot(P a,P b){
	return real(a*conj(b));
}

double cross(P a,P b){
	return imag(a*conj(b));
}


int ccw(P a, P b, P c) {
	b -= a; c -= a;
	if (cross(b, c) > 0)   return +1;	// a ??? b ??§???????¨??????????????????? b ??? c(???)
	if (cross(b, c) < 0)   return -1;	// a ??? b ??§????¨??????????????????? b ??? c(???)
	if (dot(b, c) < 0) return +2;    	// a???b??§????????????a??????????¶???????b???c(c--a--b)
	if (norm(b) < norm(c)) return -2;	// a???b??§????????????b???c(a--b--c)
	return 0;							// a???b??§????????????b???c(????????? b == c)
}

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

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 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];
	return m[0] + B / A * (m[1] - m[0]);
}

P in(){
	double x,y;
	cin >> x >> y;
	return P(x,y);
}



struct Instance{
	P s,g;
	vector<L> ls;
};


double ans;
int debug;
double test(const vector<Instance> &c,vector<int> id){
	/*
	if( id != vector<int>{0,1,0,1,0} ) return 1e9;
	
	//cout << id[0] << endl;
	//cout << c.front().s << "->" << c.back().g << endl;
	cout << "new instance[";
	for(int j : id ) cout << j << " ";
	cout << "]" << endl;
	for(int i = 0 ; i < c.size() ; i++){
		cout << "___" << i << "th___" << endl;
		cout << "start: " << c[i].s << endl;
		cout << "goal: " << c[i].g << endl;
		
		if( i == debug ){
			fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",c.front().s.real(),c.front().s.imag(),c.back().g.real(),c.back().g.imag());
			for( auto j : c[i].ls ){
				fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",j[0].real(),j[0].imag(),j[1].real(),j[1].imag());
				//cout << j[0] << "-" << j[1] << endl;
			}
		}
	}
	//*/
	
	
	P cur = c.front().s;
	P t = c.back().g;
	int idx = -1;
	double ans = abs(cur-t);
	for(int i = 0 ; i < c.size() ; i++){
/*
		fprintf(stderr,"circle(%.2lf,%.2lf)\n",cur.real(),cur.imag());
		fprintf(stderr,"circle(%.2lf,%.2lf)\n",		t.real(),t.imag());

		if( i == debug ){
			fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",c.front().s.real(),c.front().s.imag(),c.back().g.real(),c.back().g.imag());
			for( auto j : c[i].ls ){
				fprintf(stderr,"line(%.2lf,%.2lf,%.2lf,%.2lf)\n",j[0].real(),j[0].imag(),j[1].real(),j[1].imag());
				//cout << j[0] << "-" << j[1] << endl;
			}
		}
//*/
		vector< pair<double,int> > dst;
		P nextp;
		for(int j = 0 ; j < n ; j++){
			if( idx == j ) continue;
			
			if( intersectSS(c[i].ls[j],L(cur,t)) ){
				P cp = crosspoint(L(cur,t),c[i].ls[j]);
				if( i < id.size() and j == id[i] ) nextp = cp;
				dst.push_back({abs(cur-cp),j});
				//cout << cur << "-" << t << " " << c[i].ls[j][0] << "-" << c[i].ls[j][1] << " " << cp << '(' << j << " [" << i << "]" << "btw, " << abs(cur-cp) << endl;
			}
		}
		sort(dst.begin(),dst.end());
		assert( !dst.size() or dst.front().first > 1e-9 );
		if( i < id.size() ){
//			cout << "ll" << dst.front().first << endl;
			if( dst.size() == 0 ){
				//cout << "fail must hit " << id[i] << " but no hit" << endl;
				return 1e9;
			}
			if( dst.front().second != id[i] ){
				//cout << "fail must hit " << id[i] << " but " << dst.front().second << endl;
				return 1e9;
			}
			cur = nextp;
		}else{
		
			if( dst.size() != 0 ){
				//cout << "fail some wall exits" << endl;
				return 1e9;
			}
		}
		if( i < id.size() ) {
			idx = id[i];
		}
		
	}
	
	//*/
	//exit(0);
	return ans;
}


void dfs(vector<Instance> c,int ref,vector<int> ids){
	
	if(ref < 0 ) return;
	ans = min(ans,test(c,ids));
	
	for(int i = 0 ; i < n ; i++){
		if( ids.size() and ids.back() == i ) continue;
		Instance d = c.back();
		vector<int> nid = ids;
		d.s = reflection(c.back().ls[i],c.back().s);
		d.g = reflection(c.back().ls[i],c.back().g);
		nid.push_back(i);
		vector<Instance> newc = c;
		
		for(int j = 0 ; j < n ; j++){
			d.ls[j][0] = reflection(c.back().ls[i],c.back().ls[j][0]);
			d.ls[j][1] = reflection(c.back().ls[i],c.back().ls[j][1]);
		}
		newc.push_back(d);
		dfs(newc,ref-1,nid);
	}
}
int main(int argc,char *vvv[]){
	//if( argc >= 2 ){
	//	debug = atoi(vvv[1]);
	//}
	while(cin >> n && n){
		ans = 1e18;
		Instance inp;
		for(int i = 0 ; i < n ; i++){
			P a = in();
			P b = in();
			inp.ls.push_back(L(a,b));
		}
		inp.g = in();
		inp.s = in();
		dfs({inp},5,{});
		printf("%.10lf\n",ans);
		//cerr << "TODO:" << 5 << endl;
	}
}

Measured memory_bytes: 3348