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

typedef complex<double> P;
typedef pair<P,P> L;

const double EPS = 1e-7;
const double INF = 1e+9;

struct state{
  int pos;
  P p;
  state(int pos=0, P p=P(0,0)):pos(pos),p(p){}
};

bool equal(double a, double b){ return fabs(a-b) < EPS; }

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

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

P proj(P p, L l){
    return l.first + dot(p - l.first, l.second - l.first) / norm(l.second - l.first) * (l.second - l.first);
}

P reflect(P p, L l){
  return p + (proj(p,l) - p) * 2.0;
}

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;
  if(cross(b,c) < -EPS) return -1;
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersectSP(L s, P p){ 
  return abs(s.first-p) + abs(s.second-p) - abs(s.second-s.first) < EPS; 
}

bool isIntersect(L s1, L s2){
  
  //ccw ??????????????????????????¨, ????????????????????´?????????????????¨??????????????????????????????
  if(max(real(s1.first), real(s1.second)) + EPS < min(real(s2.first), real(s2.second)) ||
     max(imag(s1.first), imag(s1.second)) + EPS < min(imag(s2.first), imag(s2.second)) ||
     max(real(s2.first), real(s2.second)) + EPS < min(real(s1.first), real(s1.second)) ||
     max(imag(s2.first), imag(s2.second)) + EPS < min(imag(s1.first), imag(s1.second))) return false;

  // ????????????
  if(isIntersectSP(s1, s2.first) || isIntersectSP(s1, s2.second) || isIntersectSP(s2, s1.first) || isIntersectSP(s2, s1.second)) return false;

  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

P crossPoint(L l, L m){
  double A = cross(l.second - l.first, m.second - m.first);
  double B = cross(l.second - l.first, l.second - m.first);
  if(fabs(A) < EPS && fabs(B) < EPS) return m.first;
  else if(fabs(A) >= EPS) return m.first + B / A * (m.second - m.first);
}


int n;
vector<L> lines;
P st, go;

void dfs(int cnt, vector<state> &v, double &ans, int now_n){
  vector<state> sv;
  P p = st, next;
  double sum_d = 0;
  bool f = true;

  sv.push_back(state(-1, st));
  for(int i=(int)v.size()-1;i>0;i--){
    if(!isIntersect(lines[v[i].pos], L(p, v[i].p))){
      f = false;
      break;
    }
    next = crossPoint(lines[v[i].pos], L(p, v[i].p));    
    for(int j=0;j<n;j++){
      if(isIntersect(lines[j], L(p, next))){
        f = false;
        break;
      }
    }
    if(!f) break;
    sum_d += abs(p - next);
    p = next;
    sv.push_back(state(v[i].pos, p));
  }
  
  if(f){
    sv.push_back(state(-2, go));
    for(int i=0;i<n;i++){
      if(isIntersect(lines[i], L(p, go))){
        f = false;
        break;
      }
    }
  }

  //????????????????????????
  if(f){
    for(int i=1;i<(int)sv.size()-1;i++){
      assert(sv[i].pos >= 0);
      L l = lines[sv[i].pos];
      if(ccw(l.first, l.second, sv[i-1].p) != ccw(l.first, l.second, sv[i+1].p)){
        f = false;
        break;
      }
    }
  }

  if(f) ans = min(ans, sum_d + abs(p - go));
    
  for(int i=0;i<n;i++){
    if(now_n == i || cnt >= 5) continue;
    v.push_back(state(i, reflect(v[v.size()-1].p, lines[i])));
    dfs(cnt+1, v, ans, i);
    v.pop_back();
  }
}

double solve(){
  double ans = INF;
  vector<state> v;
  v.push_back(state(-2, go));
  dfs(0, v, ans, -1);
  return ans;
}

int main(){
  double x,y,x2,y2;
  while(cin >> n && n){
    lines.clear();
    for(int i=0;i<n;i++){
      cin >> x >> y >> x2 >> y2;
      lines.push_back(L(P(x, y), P(x2, y2)));
    }
    cin >> x >> y;
    go = P(x, y);
    cin >> x >> y;
    st = P(x, y);
    printf("%.14f\n",solve());
  }
}

Measured memory_bytes: 1280