#include<bits/stdc++.h>
#define MAX 200
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
  bool operator==(Segment s){ 
    if(p1==s.p1 && p2==s.p2)return true;
    if(p1==s.p2 && p2==s.p1)return true;
    return false;
  }
};
typedef Segment Line;

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

bool isParallel(Segment s,Segment t){
  return equals(cross(s.p1-s.p2,t.p1-t.p2),0.0);
}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return 1;
  if(cross(a,b)<-eps)return -1;
  if(dot(a,b)<-eps)return 2;
  if(a.norm()<b.norm())return -2;
  return 0;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 &&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPointLL(Line a,Line b){
  double A=cross(a.p2-a.p1,b.p2-b.p1);
  double B=cross(a.p2-a.p1,a.p2-b.p1);
  if(abs(A)<eps || abs(B)<eps)return b.p1;
  return b.p1+(b.p2-b.p1)*(B/A);
}

int contains(Polygon g,Point p){
  int n=g.size();
  bool x=false;
  for(int i=0;i<n;i++){
    Vector a=g[i]-p,b=g[(i+1)%n]-p;
    if(abs(cross(a,b))<eps && dot(a,b)<eps)return 1;
    if(a.y>b.y)swap(a,b);
    if(a.y<eps && eps<b.y && cross(a,b)>eps)x=!x;
  }
  if(x)return 2;
  return 0;
}

Polygon reflect(Polygon p,Line L){
  Polygon res;
  for(int i=0;i<p.size();i++)res.push_back(reflect(L,p[i]));
  reverse(res.begin(),res.end());
  return res;
}

vector<Point> unique(vector<Point> vp){
  sort(vp.begin(),vp.end());
  vector<Point> res;
  res.push_back(vp[0]);
  for(int i=1;i<vp.size();i++){
    if(!(vp[i]==res.back()))res.push_back(vp[i]);
  }
  return res;
}

int n;
Polygon buildings[100];
Point s,t,rs,rt;
Line L;
vector<pdi> e[MAX];
Polygon p1,p2;
vector<Point> vp;

void init(){
  FOR(i,0,n)buildings[i].clear();
  vp.clear();
  p1.clear();
  p2.clear();
  FOR(i,0,MAX)e[i].clear();
}

void add_edge(int from,int to,double cost){
  e[from].pb(mp(cost,to));
  e[to].pb(mp(cost,from));
}

bool check(Point a,Point b){
  Segment s1=Segment(a,b);
  FOR(i,0,p1.size()){
    Segment s2=Segment(p1[i],p1[(i+1)%p1.size()]);
    if(isParallel(s1,s2))continue;
    if(intersect(s1,s2)){
      Point c=getCrossPointLL(s1,s2);
      if(!(c==a) && !(c==b))return false;
    }
  }
  FOR(i,0,p2.size()){
    Segment s2=Segment(p2[i],p2[(i+1)%p2.size()]);
    if(isParallel(s1,s2))continue;
    if(intersect(s1,s2)){
      Point c=getCrossPointLL(s1,s2);
      if(!(c==a) && !(c==b))return false;
    }
  }
  Point m=a+(b-a)/2;
  if(contains(p1,m)==0)return false;
  if(contains(p2,m)==0)return false;
  return true;
}

double dijkstra(int s,int t){
  double d[MAX];
  fill(d,d+MAX,inf);
  priority_queue<pdi,vector<pdi>,greater<pdi> > pq;
  pq.push(mp(0,s));
  d[s]=0;

  while(pq.size()){
    pdi u=pq.top();
    pq.pop();
    if(d[u.s]<u.f)continue;
    if(u.s==t)return u.f;

    FOR(i,0,e[u.s].size()){
      pdi next=e[u.s][i];
      if(d[u.s]+next.f<d[next.s]){
        d[next.s]=d[u.s]+next.f;
        pq.push(mp(d[next.s],next.s));
      }
    }
  }
  return -1;
}

double solve(){
  rs=reflect(L,s);
  rt=reflect(L,t);
  FOR(i,0,n){
    if(contains(buildings[i],s)!=0 &&
       contains(buildings[i],t)!=0 )p1=buildings[i];
    if(contains(buildings[i],rs)!=0 && 
       contains(buildings[i],rt)!=0 )p2=buildings[i];
  }
  if(p2.size()==0)return -1;
  p2=reflect(p2,L);
  FOR(i,0,p1.size())vp.pb(p1[i]);
  FOR(i,0,p2.size())if(contains(p1,p2[i])!=0)vp.pb(p2[i]);
  vp=unique(vp);
  vp.pb(s);
  vp.pb(t);
  FOR(i,0,vp.size()){
    FOR(j,i+1,vp.size()){
      if(check(vp[i],vp[j]))add_edge(i,j,abs(vp[i]-vp[j]));
    }
  }
  return dijkstra(vp.size()-2,vp.size()-1);
}

int main()
{
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    FOR(i,0,n){
      int m;
      Polygon p;
      cin>>m;
      FOR(j,0,m){
        int x,y;
        cin>>x>>y;
        p.pb(Point(x,y));
      }
      buildings[i]=p;
    }
    cin>>s.x>>s.y>>t.x>>t.y;
    cin>>L.p1.x>>L.p1.y>>L.p2.x>>L.p2.y;
    double ans=solve();
    if(ans==-1)cout<<"impossible"<<endl;
    else pd(ans);
  }
  return 0;
}
### Prompt

Construct a Cpp code solution to the problem outlined:

As a proud hero, you are finally about to reach the Demon King. However, in order to reach the throne where the Demon King is, you must clear the final map prepared by the Demon King.

In this map, everything changes like a two-dimensional plan view from the sky. Humans transform into just points on this map. The map is divided into two areas by a straight line. Then, when there is a person in one area, a mirror image of the person is projected at a position in the other area that is line-symmetric with respect to a straight line.

There are multiple buildings in each of the two areas. Even though it is a building, in this map, it is a polygon made by connecting several points, and the inside surrounded by the sides and the top of the side are the inside of the building. Buildings, unlike humans, do not create mirror images in other areas.

When you break into this map, the Demon King's magic will lock you inside one of the buildings. You can only clear the map by moving to one escape point inside the detained building. In addition, you are cursed by the Demon King and restricted in your movements. The limitation is that your location and the location of your mirror image must be inside one of the buildings. As long as you follow this restriction, you are free to move inside the building.

Now, you must clear this map as soon as possible and defeat the Demon King who is destroying the world. Given your initial position, find the shortest path distance to get to the escape point. However, if you cannot move to the escape point, you will not be able to escape from the eternal map and will only decay.

Input

The input consists of multiple datasets. The format of each data set is as follows.


N
BUILDING1
...
BUILDINGN
SX SY GX GY
LX1 LY1 LX2 LY2


All inputs are integer values. Moreover, it may be assumed that all the coordinate information is -10,000 <= x, y <= 10,000.

N (1 <= N <= 100) is the number of buildings. Next, information on N buildings is entered. BUILDINGi is a polygon that is input in the following format.


M
X1 Y1
...
XM YM


M (3 <= M <= 50) represents the number of vertices of the polygon. Then M vertices, (Xi, Yi) are input counterclockwise. The line segment connecting the vertices of (Xi, Yi) and (Xi + 1, Yi + 1) is one side of the polygon. However, the first vertex is connected to the M-th vertex. It can be assumed that the three consecutive vertices of a polygon do not line up. In addition, each side of the polygon is input so that it does not touch or intersect with any side other than the adjacent sides. Each polygon does not touch, intersect, or contain other polygons.

After the building information is entered, the start point (SX, SY) and escape point (GX, GY) information is entered. Both the starting point and the escape point are inside the same building. However, please note that the mirror images of the starting point and the escape point do not always exist inside the building. In this case, of course, the map cannot be cleared. The start point and the escape point always exist at different positions.

Finally, the straight line information is input. A straight line is represented by two points (LX1, LY1) and (LX2, LY2) existing on the straight line. These two points are always in different positions. It may be assumed that the straight line does not touch or intersect any building.

The end of the input is given on a line with only one 0.

Output

For each dataset, output the shortest distance from the start point to the escape point. The error in the answer must not exceed 0.00000001 (10-8). Any number of digits after the decimal point may be output as long as the precision conditions are met.

If you can't reach the escape point, print "impossible".

Sample Input


2
3
1 1
twenty two
1 2
3
-1 1
-1 2
-twenty two
1 1 2 2
0 0 0 1
2
Ten
1 1
7 1
7 5
5 5
5 3
6 3
6 2
3 2
3 5
1 5
Ten
-1 1
-1 5
-3 5
-3 3
-twenty three
-twenty two
-5 2
-5 5
-7 5
-7 1
2 4 6 4
0 0 0 1
2
7
-7 0
-5 0
-4 3
-3 0
-Ten
-14
-7 4
3
Ten
7 0
7 4
3 1 5 2
0 0 0 1
0


Output for Sample Input


1.4142135623730951
8.0 8.0
impossible impossible


The following figures show the arrangement of each sample. In Figures G-1 and G-2, the red path shows the hero's own path, and the blue path shows the hero's mirror image path. In Figure G-3, it is not possible to reach the escape point from the start point.

<image>

Figure G-1: First sample

<image>

Figure G-2: Second sample

<image>

Figure G-3: Third sample





Example

Input

2
3
1 1
2 2
1 2
3
-1 1
-1 2
-2 2
1 1 2 2
0 0 0 1
2
10
1 1
7 1
7 5
5 5
5 3
6 3
6 2
3 2
3 5
1 5
10
-1 1
-1 5
-3 5
-3 3
-2 3
-2 2
-5 2
-5 5
-7 5
-7 1
2 4 6 4
0 0 0 1
2
7
-7 0
-5 0
-4 3
-3 0
-1 0
-1 4
-7 4
3
1 0
7 0
7 4
3 1 5 2
0 0 0 1
0


Output

1.4142135623730951
8.0
impossible

### Response

```cpp
#include<bits/stdc++.h>
#define MAX 200
#define inf 1<<29
#define linf 1e18
#define eps (1e-8)
#define mod 1000000007
#define pi M_PI
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define pd(a) printf("%.10f\n",(double)(a))
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(a)-1;(b)<=i;i--)
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<double,int> pdi;
typedef vector<int> vi;
typedef vector<pii> vpi;
const int dx[8]={1,0,-1,0,1,1,-1,-1};
const int dy[8]={0,1,0,-1,1,-1,1,-1};

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):x(x),y(y){}

  Point operator+(Point p){ return Point(x+p.x,y+p.y);}
  Point operator-(Point p){ return Point(x-p.x,y-p.y);}
  Point operator*(double k){ return Point(x*k,y*k);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;
typedef vector<Point> Polygon;

class Segment{
public:
  Point p1,p2;
  Segment(Point p1=Point(),Point p2=Point()):p1(p1),p2(p2){}
  bool operator==(Segment s){ 
    if(p1==s.p1 && p2==s.p2)return true;
    if(p1==s.p2 && p2==s.p1)return true;
    return false;
  }
};
typedef Segment Line;

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

bool isParallel(Vector a,Vector b){
  return equals(cross(a,b),0.0);
}

bool isParallel(Segment s,Segment t){
  return equals(cross(s.p1-s.p2,t.p1-t.p2),0.0);
}

Point project(Segment s,Point p){
  Vector base=(s.p2-s.p1);
  double r=(dot(p-s.p1,base)/base.norm());
  return (s.p1+base*r);
}

Point reflect(Segment s,Point p){
  return p+(project(s,p)-p)*2;
}

int ccw(Point p0,Point p1,Point p2){
  Vector a=p1-p0;
  Vector b=p2-p0;
  if(cross(a,b)>eps)return 1;
  if(cross(a,b)<-eps)return -1;
  if(dot(a,b)<-eps)return 2;
  if(a.norm()<b.norm())return -2;
  return 0;
}

bool intersect(Point p1,Point p2,Point p3,Point p4){
  return (ccw(p1,p2,p3)*ccw(p1,p2,p4)<=0 &&
          ccw(p3,p4,p1)*ccw(p3,p4,p2)<=0);
}

bool intersect(Segment s1,Segment s2){
  return intersect(s1.p1,s1.p2,s2.p1,s2.p2);
}

Point getCrossPointLL(Line a,Line b){
  double A=cross(a.p2-a.p1,b.p2-b.p1);
  double B=cross(a.p2-a.p1,a.p2-b.p1);
  if(abs(A)<eps || abs(B)<eps)return b.p1;
  return b.p1+(b.p2-b.p1)*(B/A);
}

int contains(Polygon g,Point p){
  int n=g.size();
  bool x=false;
  for(int i=0;i<n;i++){
    Vector a=g[i]-p,b=g[(i+1)%n]-p;
    if(abs(cross(a,b))<eps && dot(a,b)<eps)return 1;
    if(a.y>b.y)swap(a,b);
    if(a.y<eps && eps<b.y && cross(a,b)>eps)x=!x;
  }
  if(x)return 2;
  return 0;
}

Polygon reflect(Polygon p,Line L){
  Polygon res;
  for(int i=0;i<p.size();i++)res.push_back(reflect(L,p[i]));
  reverse(res.begin(),res.end());
  return res;
}

vector<Point> unique(vector<Point> vp){
  sort(vp.begin(),vp.end());
  vector<Point> res;
  res.push_back(vp[0]);
  for(int i=1;i<vp.size();i++){
    if(!(vp[i]==res.back()))res.push_back(vp[i]);
  }
  return res;
}

int n;
Polygon buildings[100];
Point s,t,rs,rt;
Line L;
vector<pdi> e[MAX];
Polygon p1,p2;
vector<Point> vp;

void init(){
  FOR(i,0,n)buildings[i].clear();
  vp.clear();
  p1.clear();
  p2.clear();
  FOR(i,0,MAX)e[i].clear();
}

void add_edge(int from,int to,double cost){
  e[from].pb(mp(cost,to));
  e[to].pb(mp(cost,from));
}

bool check(Point a,Point b){
  Segment s1=Segment(a,b);
  FOR(i,0,p1.size()){
    Segment s2=Segment(p1[i],p1[(i+1)%p1.size()]);
    if(isParallel(s1,s2))continue;
    if(intersect(s1,s2)){
      Point c=getCrossPointLL(s1,s2);
      if(!(c==a) && !(c==b))return false;
    }
  }
  FOR(i,0,p2.size()){
    Segment s2=Segment(p2[i],p2[(i+1)%p2.size()]);
    if(isParallel(s1,s2))continue;
    if(intersect(s1,s2)){
      Point c=getCrossPointLL(s1,s2);
      if(!(c==a) && !(c==b))return false;
    }
  }
  Point m=a+(b-a)/2;
  if(contains(p1,m)==0)return false;
  if(contains(p2,m)==0)return false;
  return true;
}

double dijkstra(int s,int t){
  double d[MAX];
  fill(d,d+MAX,inf);
  priority_queue<pdi,vector<pdi>,greater<pdi> > pq;
  pq.push(mp(0,s));
  d[s]=0;

  while(pq.size()){
    pdi u=pq.top();
    pq.pop();
    if(d[u.s]<u.f)continue;
    if(u.s==t)return u.f;

    FOR(i,0,e[u.s].size()){
      pdi next=e[u.s][i];
      if(d[u.s]+next.f<d[next.s]){
        d[next.s]=d[u.s]+next.f;
        pq.push(mp(d[next.s],next.s));
      }
    }
  }
  return -1;
}

double solve(){
  rs=reflect(L,s);
  rt=reflect(L,t);
  FOR(i,0,n){
    if(contains(buildings[i],s)!=0 &&
       contains(buildings[i],t)!=0 )p1=buildings[i];
    if(contains(buildings[i],rs)!=0 && 
       contains(buildings[i],rt)!=0 )p2=buildings[i];
  }
  if(p2.size()==0)return -1;
  p2=reflect(p2,L);
  FOR(i,0,p1.size())vp.pb(p1[i]);
  FOR(i,0,p2.size())if(contains(p1,p2[i])!=0)vp.pb(p2[i]);
  vp=unique(vp);
  vp.pb(s);
  vp.pb(t);
  FOR(i,0,vp.size()){
    FOR(j,i+1,vp.size()){
      if(check(vp[i],vp[j]))add_edge(i,j,abs(vp[i]-vp[j]));
    }
  }
  return dijkstra(vp.size()-2,vp.size()-1);
}

int main()
{
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    FOR(i,0,n){
      int m;
      Polygon p;
      cin>>m;
      FOR(j,0,m){
        int x,y;
        cin>>x>>y;
        p.pb(Point(x,y));
      }
      buildings[i]=p;
    }
    cin>>s.x>>s.y>>t.x>>t.y;
    cin>>L.p1.x>>L.p1.y>>L.p2.x>>L.p2.y;
    double ans=solve();
    if(ans==-1)cout<<"impossible"<<endl;
    else pd(ans);
  }
  return 0;
}
```