Problem: A laser beam generator, a target object and some mirrors are placed on a plane. The mirrors stand upright on the plane, and both sides of the mirrors are flat and can reflect beams. To point the beam at the target, you may set the beam to several directions because of different reflections. Your job is to find the shortest beam path from the generator to the target and answer the length of the path.

Figure G-1 shows examples of possible beam paths, where the bold line represents the shortest one.

<image>

Figure G-1: Examples of possible paths

Input

The input consists of a number of datasets. The end of the input is indicated by a line containing a zero.

Each dataset is formatted as follows. Each value in the dataset except n is an integer no less than 0 and no more than 100.

> n
>  PX1 PY1 QX1 QY1
>  ...
>  PXn PYn QXn QYn
>  TX TY
>  LX LY
>

The first line of a dataset contains an integer n (1 ≤ n ≤ 5), representing the number of mirrors. The following n lines list the arrangement of mirrors on the plane. The coordinates (PXi, PYi) and (QXi, QYi) represent the positions of both ends of the mirror. Mirrors are apart from each other. The last two lines represent the target position (TX, TY) and the position of the beam generator (LX, LY). The positions of the target and the generator are apart from each other, and these positions are also apart from mirrors.

The sizes of the target object and the beam generator are small enough to be ignored. You can also ignore the thicknesses of mirrors.

In addition, you can assume the following conditions on the given datasets.

* There is at least one possible path from the beam generator to the target.
* The number of reflections along the shortest path is less than 6.
* The shortest path does not cross or touch a plane containing a mirror surface at any points within 0.001 unit distance from either end of the mirror.
* Even if the beam could arbitrarily select reflection or passage when it reaches each plane containing a mirror surface at a point within 0.001 unit distance from one of the mirror ends, any paths from the generator to the target would not be shorter than the shortest path.
* When the beam is shot from the generator in an arbitrary direction and it reflects on a mirror or passes the mirror within 0.001 unit distance from the mirror, the angle θ formed by the beam and the mirror satisfies sin(θ) > 0.1, until the beam reaches the 6th reflection point (exclusive).



Figure G-1 corresponds to the first dataset of the Sample Input below. Figure G-2 shows the shortest paths for the subsequent datasets of the Sample Input.

<image>

Figure G-2: Examples of the shortest paths

Output

For each dataset, output a single line containing the length of the shortest path from the beam generator to the target. The value should not have an error greater than 0.001. No extra characters should appear in the output.

Sample Input


2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0


Output for the Sample Input


180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809






Example

Input

2
30 10 30 75
60 30 60 95
90 0
0 100
1
20 81 90 90
10 90
90 10
2
10 0 10 58
20 20 20 58
0 70
30 0
4
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
24 0
24 64
5
8 0 8 60
16 16 16 48
16 10 28 30
16 52 28 34
100 0 100 50
24 0
24 64
0


Output

180.27756377319946
113.13708498984761
98.99494936611666
90.50966799187809
90.50966799187809

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
using namespace std;
#define r(i,n) for(int i=0;i<n;i++)
typedef double D;
typedef complex<D> P;
typedef pair<P,P>L;
typedef vector<L> VP;
const D EPS = 1e-9;
#define mk make_pair
#define X real()
#define Y imag()
#define LE(n,m) ((n) < (m) + EPS)
#define GE(n,m) ((n) + EPS > (m))
#define EQ(n,m) (abs((n)-(m)) < EPS)
D ans,sx,sy,gx,gy,x,y,xx,yy;
VP v,t;
int num[7];
int n;
D dot(P a,P b){return (conj(a)*b).X;}
D cross(P a,P b){return (conj(a)*b).Y;}
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 isecSS(P a1, P a2, P b1, P b2){
  return ccw(a1,a2,b1)*ccw(a1,a2,b2)<=0 &&
         ccw(b1,b2,a1)*ccw(b1,b2,a2)<=0;
}
P proj(P a1,P a2,P p){
  return a1+ dot(a2-a1,p-a1)/norm(a2-a1)*(a2-a1);
}
P reflection(P a1, P a2, P p) {
  return 2.0*proj(a1, a2, p) - p;
}
P crosspointSS(P a1,P a2,P b1,P b2){
  P base=b2-b1;
  double d1=abs(cross(base,a1-b1));
  double d2=abs(cross(base,a2-b1));
  double t=d1/(d1+d2);
  return a1+(a2-a1)*t;
}
bool isecSP(P a1, P a2, P b) {
  //return !ccw(a1, a2, b);
   return abs(a1 - b) + abs(a2 - b) - abs(a2 - a1) < EPS;  //Perfect
}
D distSP(P a1, P a2, P p) {
  P r = proj(a1, a2, p);
  if (isecSP(a1, a2, r)) return abs(r-p);
  return min(abs(a1-p), abs(a2-p));
}
int n_max,flag,cnt;
 
VP ch,c7[8];
P c8[9];
P start, en;
vector<pair<double,int> >vv;

void dfs2(int dep){
 
 
  r(i,n)if(i!=num[dep]){
    if(!(dep&&i==num[dep-1]))c7[dep].push_back(t[i]);
  }
 
   
  if(n_max==dep){
    vv.clear();
    r(i,ch.size()){
      if(!isecSS( ch[i].first, ch[i].second, start, en)) flag ++;
      vv.push_back(mk(distSP(ch[i].first,ch[i].second,en),i));
    }
    sort(vv.begin(),vv.end());
    r(i,(int)vv.size()-1){
      if(vv[i].second<vv[i+1].second)flag++;
    }

    c8[0]=start;
    for(int i=0;i<dep;i++){
      c8[i+1]=crosspointSS(start,en,ch[i].first,ch[i].second);
    }
    c8[dep+1]=en;
    
    r(i,c7[dep].size()){
      if(isecSS( c7[dep][i].first, c7[dep][i].second, c8[dep], c8[dep+1])) flag ++;
    }
    return ;
  }
 
  ch.push_back(t[num[dep]]);
 
   P ss = t[num[dep]].first;
   P gg = t[num[dep]].second;
 
    
 
  for(int i=0;i<n;i++){
    if(num[dep]!=i){
      t[i].first=reflection(ss,gg,t[i].first);
      t[i].second=reflection(ss,gg,t[i].second);
    }
  }
  en = reflection(ss,gg,en);
   
  dfs2(dep+1);
 
  if(flag)return ;
 
 
  r(i,c7[dep].size()){
      if(isecSS( c7[dep][i].first, c7[dep][i].second, c8[dep], c8[dep+1])) flag ++;
  }
  return ;
}
void dfs1(int dep,int pre){
 
  if(dep==6) return ;
 
  start=P(sx,sy);
  en=P(gx,gy);
  ch.clear();
  t.clear();
  r(i,8)c7[i].clear();
  flag = 0;
  n_max = dep;
  r(i,n)t.push_back(v[i]);
   
  dfs2(0);
 
  if(!flag)ans=min(ans,abs(start-en));
 
  for(int i=0;i<n;i++){
    if(pre!=i){
      num[dep]=i;
      dfs1(dep+1,i);
      num[dep]=-1;
    }
  }
}
 
int main(){
  while(cin>>n,n){
    memset(num,-1,sizeof(num));
    ans=1e13;
    v.clear();
    r(i,n){
      cin >> x >> y >> xx >> yy;
      v.push_back( mk( P(x,y) , P(xx,yy) ) );
    }
    cin >> gx >> gy >> sx >> sy ;
    dfs1(0,-1);
    printf("%.13f\n",ans);
  }
}