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;
typedef complex<double> P;
 
double eps=1e-8;
 
bool eq(double a,double b){
  return (-eps<a-b&&a-b<eps);
}
 
bool eq(P a,P b){
  return (abs(a-b)<eps);
}
 
double dot(P a,P b){
  return real(b*conj(a));
}
 
double cross(P a,P b){
  return imag(b*conj(a));
}
     
bool isParallel(P a,P b){
  return eq( cross(a,b) , 0 );
}
 
 
struct S{
  P p,q;
  S(P a=P(0,0),P b=P(0,0)):p(a),q(b){}
  P base(){    return q-p;  }
};
 
typedef S L;
 
double getDistanceLP(L l,P p){
  P a=l.p,b=l.q;
  return abs( cross(b-a,p-a) ) / abs(b-a);
}
 
double getDistanceSP(S s,P p){
  P a=s.p;
  P b=s.q;
  if( dot(b-a,p-a) < eps )return abs(p-a);
  if( dot(a-b,p-b) < eps )return abs(p-b);
  return getDistanceLP(s,p);
}
 
P reflect(S s,P p){
  P a=s.p;
  P b=s.q;
  p-=a;
  b-=a;
  return a+conj(p/b)*b;
}
 
bool onLine(L l,P p){
  P a=l.p;
  P b=l.q;
  return eq(0, cross(p-a,b-a) );
}
 
bool onSegment(S s,P p){
  P a=s.p;
  P b=s.q;
  return eq( abs(a-b) , abs(p-a) + abs(p-b) );
}
 
P getCrossPoint(S s1,S s2){
  P a=s1.p, b=s1.q;
  P c=s2.p, d=s2.q;
  a-=d,b-=d,c-=d;
  return d+a+(b-a)*imag(a/c)/imag(a/c-b/c);
}
 
bool isIntersectLS(L li,S se){
  P a=li.p;
  P b=li.q;
  double A=cross(b-a,se.p-a);
  double B=cross(b-a,se.q-a);
  return (A*B<eps);
}
 
P input(){
  double x,y;
  cin>>x>>y;
  return P(x,y);
}
 
int N;
S t[5];
P si,ti;
int tl[10];
double ans;
 
double calc(P p,P v,int depth){
 
  if( eq(p,ti) ) return 0;
   
  P np,nv;
   
  if(depth>6)return 1e20;
   
  double mini=1e20;
  for(int i=0;i<N;i++){
    S seg=t[i];
    if(onSegment(seg,p))continue;
    L li=L(p,p+v);
    if( !isIntersectLS(li,seg) )continue;
    P k=getCrossPoint( li, seg );
    assert( onSegment(seg,k) );
    assert( onLine(li,k) );
    if( dot(k-p,v) < 0 )continue;
    if(mini>abs(k-p)){
      mini=abs(k-p);
      np=k;
      nv=reflect(seg,k+v)-k;
    }
  }
 
  if( isParallel(v,ti-p) && dot(v,ti-p) > 0 ){
    if( mini > abs(ti-p)){
      return abs(ti-p);
    }
  }
 
  if(mini==1e20)return 1e20;
  return mini+calc(np,nv,depth+1);
}
 
P ansve;
void check(int size,P target){
  P v=target-si;
  if( abs(v) < eps )return;
  double dist=calc(si,v,0);
  if(ans>dist){
    ans=dist;
    ansve=v;
  }
}
 
void dfs(int depth, P target){
  check(depth,target);
  if(depth==6)return;
  for(int i=0;i<N;i++){
    dfs(depth+1, reflect(t[i],target) );
  }
}
 
int main(){
  while(1){
    cin>>N;
    if(N==0)break;
    for(int i=0;i<N;i++){
      P a=input();
      P b=input();
      t[i]=S(a,b);
    }
    ti=input();
    si=input();
    ans=1e20;
    dfs(0,ti);
    printf("%.10f\n",ans);
  }
  return 0;
}