#include <bits/stdc++.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

using namespace std;

using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

const R INF = 1E40L;
const R PI = acos(-1.0L);
using P=complex<R>;
const P O=0.0L;
using L=struct{P s,t;};

auto& operator >> (istream& is,P& p){ R x,y;is >> x >> y; p=P(x,y); return is;}
auto& operator << (ostream& os,P& p){ os << real(p) << " " << imag(p); return os;}

inline R dot(P o,P a,P b){return real(conj(a-o)*(b-o));}
inline R det(P o,P a,P b){return imag(conj(a-o)*(b-o));}
inline int sdot(P o,P a,P b){return sgn(dot(o,a,b));}
inline int sdet(P o,P a,P b){return sgn(det(o,a,b));}

//projection verify AOJ CGL_1_A
P proj(L l,P p){ R u=real((p-l.s)/(l.t-l.s)); return (1-u)*l.s+u*l.t;}

//reflection verify AOJ CGL_1_B
P refl(L l,P p){return 2.0L*proj(l,p)-p;}

L refl(L l,L arg){ return L{refl(l,arg.s),refl(l,arg.t)};}

// crossing determination
// verified: AOJ CGL_2_B 
bool iss(L a,L b){
	int sa=sdet(a.s,a.t,b.s)*sdet(a.s,a.t,b.t);
	int sb=sdet(b.s,b.t,a.s)*sdet(b.s,b.t,a.t);
	return max(sa,sb)<0;
}

// crossing point 
// verified: AOJ CGL_2_C
P cross(L a,L b){
	R u=det(a.s,b.s,b.t)/det(O,a.t-a.s,b.t-b.s);
	return (1-u)*a.s+u*a.t;
}

int n;
L mirror[5];
P g, s;


int main(void) {

	while (cin >> n, n) {
		rep(i, n) cin >> mirror[i].s >> mirror[i].t;
		cin >> g >> s;

		R ans = INF;

		{
			bool ok = true;
			L laser = L{s,g};
			rep(i,n) if(iss(laser,mirror[i])) ok = false;
			if(ok) ans = min(ans,abs(g-s));
		}

		const int total = pow<int>(n, 5);
		rep(mask, total){
			vector<int> ary;

			{
				int cur = mask;
				rep(loop, 5) ary.push_back(cur % n), cur /= n;
			}

			bool skip = false;
			rep(i,4) if(ary[i] == ary[i+1]) skip = true;
			if(skip) continue;

			for(int m = 1; m <= 5; ++m){
				L cur_mirror[6][5];
				rep(j, n) cur_mirror[0][j] = mirror[j];

				P cs = s;
				rep(i, m) {
					rep(j, n) cur_mirror[i + 1][j] = cur_mirror[i][j];
					rep(j, n) if (j != ary[i]) cur_mirror[i + 1][j] = refl(cur_mirror[i + 1][ary[i]], cur_mirror[i + 1][j]);
					cs = refl(cur_mirror[i + 1][ary[i]],cs);
				}

				R dist = abs(g -cs);
				L laser = L{cs, g};
				bool ok = true;

				vector<R> ord;

				ord.push_back(0);
				rep(i, m) {
					L cur = cur_mirror[i + 1][ary[i]];
					if (iss(laser, cur) == false) ok = false;
					ord.push_back(abs(g - cross(laser, cur)));
				}
				ord.push_back(dist);

				rep(i, m+1) if (sgn(ord[i] - ord[i + 1]) > 0 ) ok = false;

				rep(i,m+1){
					rep(j,n){
						if(0<= i and i < m and j==ary[i]) continue;
						if(0<= i-1 and i-1 < m and j==ary[i-1]) continue;
						L cur = cur_mirror[i][j];
						if (iss(laser, cur)){
							R cur_dist = abs(g - cross(laser, cur));
							//if(mask == 195) cerr << "mirror: " << i << " " << j << " " << cur_dist << endl;
							if(sgn(cur_dist - ord[i]) > 0 and sgn(ord[i+1] -cur_dist) > 0) ok = false;
						}
					}
				}

				if (ok) ans = min(ans, dist);
				
				// DEBUG
				/*
				if(mask == 195){
					cerr << mask << " " << m << endl;
					rep(i,m) cerr << ary[i] << " ";
					cerr << endl;
					rep(i, m+1){
						rep(j,n) cerr << cur_mirror[i][j].s << " " << cur_mirror[i][j].t << endl;
						cerr << cs << endl << endl;
					}
					rep(i,m+2) cerr << "dist: " << ord[i] << endl;
					if(ok)	cerr << "update: " << dist << endl;
				}
				*/
				
			}
		}

		cout.precision(20);
		cout << fixed << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 3380