#include <iostream>
#include <cstdio>
#include <vector>
#include <complex>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <cstring>
#include <stack>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <cassert>

using namespace std;

typedef long long ll;
typedef ll li;
typedef pair<int,int> PI;
#define EPS (1e-10L)
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define F first
#define S second
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define each(it,a) for(__typeof(a.begin())it=a.begin();it!=a.end();++it)



double heron(double a, double b, double c) { double s=(a+b+c)/2; return sqrt(s*(s-a)*(s-b)*(s-c)); }
double vert(double a, double b, double c) { return heron(a, b, c)*2/a; }
double hori(double a, double b, double c) { return (a*a+b*b-c*c)/2/a; }
bool istri(double a, double b, double c) { double m=max(a, max(b, c)); return a+b+c-m>m; }

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;
namespace std{
bool operator < (const P &a, const P &b) { return make_pair(real(a), imag(a)) < make_pair(real(b), imag(b)); }
}
istream& operator >>(istream &in, P &p) { return in >> p.real() >> p.imag(); }
istream& operator >>(istream &in, L &l) { return in >> l.first >> l.second; }
istream& operator >>(istream &in, C &c) { return in >> c.first >> c.second; }

#define DI(l) ((l).second-(l).first)
#define EQ(a, b) (abs((a)-(b)) < EPS)
#define CCW(l, a) ccw((l).first, (l).second, (a))
double cross(const P &a, const P &b) { return imag(conj(a)*b); }
double dot(const P& a, const P& b) { return real(conj(a)*b); }
/* ccw(a, b, c)
 * +1: counter clockwise
 * -1: clockwise
 * +2: c--a--b    on L
 * -2:    a--b--c on L
 *  0: c is on a--b
 */
int ccw(P a, P b, P c) {
	double d = cross(b -= a, c -= a);
	return d>EPS ? 1 : d<-EPS ? -1 : dot(b,c)<-EPS ? 2 : norm(b)+EPS<norm(c) ? -2 : 0;
}
bool parallel(const L &l, const L &m) { return EQ(cross(DI(l), DI(m)), 0); }
bool sameline(const L &l, const L &m) { return parallel(l, m) && EQ(cross(DI(l), m.second-l.first), 0); }
bool intersectLL(const L &l, const L &m) { return !parallel(l, m) || sameline(l, m); }
bool intersectLP(const L &l, const P &p) { return EQ(cross(l.second-p, l.first-p), 0); }
bool intersectSS(const L &s, const L &t) { return CCW(s,t.first)*CCW(s,t.second)<=0 && CCW(t,s.first)*CCW(t,s.second)<=0; }
bool intersectSP(const L &s, const P &p) { return EQ(abs(s.first-p)+abs(s.second-p)-abs(DI(s)), 0); }
P projection(const L &l, const P &p) { return l.first + dot(p-l.first, DI(l)) / norm(DI(l)) * DI(l); } 
P reflection(const L &l, const P &p) { return 2.0 * projection(l, p) - p; }
double distanceLP(const L &l, const P &p) { return abs(p - projection(l, p)); }
double distanceLL(const L &l, const L &m) { return intersectLL(l, m) ? 0 : distanceLP(l, m.first); }
double distanceSP(const L &s, const P &p) {
	P r = projection(s, p);
	if (intersectSP(s, r)) return abs(r-p);
	return min(abs(s.first-p), abs(s.second-p));
}
double distanceSS(const L &s, const L &t) {
	if (intersectSS(s, t)) return 0;
	return min(min(distanceSP(s, t.first), distanceSP(s, t.second)), min(distanceSP(t, s.first), distanceSP(t, s.second)));
}
P crosspoint(const L &l, const L &m) {
	P a = DI(l), b = DI(m);
	double A = cross(a, b), B = cross(a, l.second-m.first);
	assert(!EQ(abs(A), 0)); // should not be parallel (if A = B = 0, then the same L)
	return m.first + B / A * b;
}

int n;
L ls[10];
P s, g;

set<double> args;

void rec(P p, int lim = 0) {
  if (lim > 6) return;
  args.insert(arg(p-s));
  rep(i, n) {
    P q = reflection(ls[i], p);
    rec(q, lim+1);
  }
}

int main() {
  while(cin >> n, n) {
    rep(i, n) cin >> ls[i];
    cin >> s >> g;
    args.clear();
    rec(g, 0);
    double ans = 1e10;
    each(it, args) {
      P c = s;
      P v = polar(1.0, *it);
      int cnt = 0;
      double len = 0;
      while(cnt < 6) {
        L line(c, c+v);
        double minlen = 1e10;
        int ind = -1;
        rep(i, n) {
          if (!parallel(line, ls[i])) {
            P cp = crosspoint(line, ls[i]);
            if (intersectSP(ls[i], cp) && dot(cp-c, v) > EPS && abs(cp-c) < minlen) {
              minlen = abs(cp-c);
              ind = i;
            }
          }
        }
        //        cout << c << " " << v << " " << g << " " << intersectLP(line, g) << endl;
        if (intersectLP(line, g) && dot(g-c, v) > EPS && abs(g-c) < minlen) {
          ans = min(ans, len + abs(g-c));
          break;
        }
        if (ind == -1) break;
        int i = ind;
        len += abs(crosspoint(line, ls[i]) - c);
        c = crosspoint(line, ls[i]);
        v = reflection(ls[i], c + v) - c;
        cnt++;
      }
    }
    printf("%.9f\n", ans);


  }
}

Measured memory_bytes: 1820