Problem: 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

Solution (in CPP):

Solution:
#include <bits/stdc++.h>

using namespace std;

#define EPS 1e-8
#define equal(a,b) (fabs(a-b) < EPS)
#define lt(a,b) (a-b < -EPS)
#define MAX_N 100
#define MAX_P 500
#define INF 1e9

struct Point{
  double x,y;

  Point(){}
  Point(double x,double y) : x(x),y(y) {}

  Point operator + (const Point &p)const{ return Point(x+p.x,y+p.y); }
  Point operator - (const Point &p)const{ return Point(x-p.x,y-p.y); }
  Point operator * (const double &k)const{ return Point(x*k,y*k); }
  Point operator / (const double &k)const{ return Point(x/k,y/k); }
  bool operator < (const Point &p)const{
    if(!equal(x,p.x)){
      return lt(x,p.x);
    }else{
      return lt(y,p.y);
    }
  }
  bool operator == (Point &p)const{
    if(equal(x,p.x) && equal(y,p.y)){
      return true;
    }
    return false;
  }
};

double dot(const Point &a,const Point &b){ return a.x*b.x+a.y*b.y; }
double cross(const Point &a,const Point &b){ return a.x*b.y - b.x*a.y; }
double norm(const Point &p){ return dot(p,p); }
double abs(const Point &p){ return sqrt(norm(p)); }
double dist(const Point &a,const Point &b){
  return sqrt(pow(a.x-b.x,2) + pow(a.y-b.y,2));
}

#define COUNTER_CLOCKWISE 1
#define CLOCKWISE -1
#define ONLINE_BACK 2
#define ONLINE_FRONT -2
#define ON_SEGMENT 0
typedef Point Vector;

int ccw(const Point &p0,const Point &p1,const Point &p2){
  Vector a = p1 - p0;
  Vector b = p2 - p0;
  if(cross(a,b) > EPS){ return COUNTER_CLOCKWISE; }
  if(cross(a,b) < -EPS){ return CLOCKWISE; }
  if(dot(a,b) < -EPS){ return ONLINE_BACK; }
  if(norm(a) < norm(b)){ return ONLINE_FRONT; }
  return ON_SEGMENT;
}

typedef Point Vector;

struct Segment{
  Point s,t;
  Segment(){}
  Segment(Point s,Point t) : s(s),t(t) {}
  bool operator == (Segment &seg)const{
    if(s == seg.s && t == seg.t){
      return true;
    }
    if(t == seg.s && s == seg.t){
      return true;
    }
    return false;
  }
};

bool isIntersectSS(const Segment &a,const Segment &b){
  Point s[2] = {a.s,a.t}, t[2] = {b.s,b.t};
  return (ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0
          && ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0);
}

Point crosspointSS(const Segment &a,const Segment &b){
  Vector va = a.t-a.s, vb = b.t-b.s;
  double d = cross(vb,va);
  return a.s+va*cross(vb,b.t-a.s)*(1.0/d);
}

struct Line{
  Point s,t;
  Line(){}
  Line(Point s,Point t) : s(s),t(t) {}
};

Point projection(const Line &l,const Point &p){
  Vector b = l.t-l.s;
  double t = dot(p-l.s,b)/norm(b);
  return l.s+b*t;
}

Point reflection(const Line &l,const Point &p){
  return p+(projection(l,p)-p)*2.0;
}

#define curr(G,i) (G[i%G.size()])
#define next(G,i) (G[(i+1)%G.size()])
typedef vector<Point> Polygon;

int containPP(const Polygon &pg,const Point &p){
  int N = pg.size();
  bool in = false;
  for(int i = 0 ; i < N ; i++){
    Point a = curr(pg,i)-p, b = next(pg,i)-p;
    if(a.y > b.y){ swap(a,b); }
    if(a.y <= 0 && 0 < b.y && cross(a,b) < 0){ in = !in; }
    if(cross(a,b) == 0 && dot(a,b) <= 0){ return 1; }
  }
  return (in ? 2 : 0);
}

struct Data{
  Point p;
  double d;
  Data(Point p,double d) : p(p),d(d) {}
  bool operator < (const Data &data)const{
    if(!equal(d,data.d)){
      return lt(d,data.d);
    }else{
      return p < data.p;
    }
  }
};

bool containPS(const Polygon &pg,Segment &s){
  vector<Data> v;
  v.push_back(Data(s.s,0));
  v.push_back(Data(s.t,dist(s.s,s.t)));
  set<Point> st;
  for(int i = 0 ; i < (int)pg.size() ; i++){
    Segment seg(curr(pg,i),next(pg,i));
    if(seg == s){ return true; }
    if(ccw(seg.s,seg.t,s.s) == 0 && ccw(seg.s,seg.t,s.t) == 0){
      return true;
    }

    if(isIntersectSS(s,seg)){
      Point cp = crosspointSS(s,seg);
      double d = dist(cp,s.s);
      if(st.find(cp) != st.end()){
        continue;
      }
      st.insert(cp);
      v.push_back(Data(cp,d));
    }
  }
  sort(v.begin(),v.end());
  for(int i = 0 ; i < (int)v.size()-1 ; i++){
    Point cp = (v[i].p + v[i+1].p) / 2.0;
    if(containPP(pg,cp) == 0){
      return false;
    }
  }
  return true;
}

struct Edge{
  int to;
  double cost;
  Edge(int to,double cost) : to(to),cost(cost) {}
};

struct State{
  int v;
  double d;
  State(int v,double d) : v(v),d(d) {}
  bool operator < (const State &s)const{
    return d > s.d;
  }
};

Polygon L,R;
vector<Edge> G[MAX_P];

double dijkstra(int s,int t){
  double dist[MAX_P];
  fill(dist,dist+MAX_P,INF);
  dist[s] = 0;
  priority_queue<State> Q;
  Q.push(State(s,0));
  while(!Q.empty()){
    State st = Q.top(); Q.pop();
    int v = st.v;
    if(lt(dist[v],st.d)){
      continue;
    }
    if(v == t){ return dist[t]; }
    for(int i = 0 ; i < (int)G[v].size() ; i++){
      Edge e = G[v][i];
      if(lt(dist[v]+e.cost,dist[e.to])){
        dist[e.to] = dist[v] + e.cost;
        Q.push(State(e.to,dist[e.to]));
      }
    }
  }
  return INF;
}

void init(){
  for(int i = 0 ; i < MAX_P ; i++){
    G[i].clear();
  }
}

int main(){
  int N;
  while(cin >> N, N){
    init();
    Polygon b[MAX_N];
    for(int i = 0 ; i < N ; i++){
      int M;
      cin >> M; b[i].resize(M);
      for(int j = 0 ; j < M ; j++){
        cin >> b[i][j].x >> b[i][j].y;
      }
    }
    Point s,t;
    Line l;
    cin >> s.x >> s.y >> t.x >> t.y;
    cin >> l.s.x >> l.s.y >> l.t.x >> l.t.y;
    int n = -1;
    for(int i = 0 ; i < N ; i++){
      if(containPP(b[i],s) != 0){
        n = i;
        L = b[n];
        break;
      }
    }
    int rn = -1;
    Point rs = reflection(l,s);
    for(int i = 0 ; i < N ; i++){
      if(containPP(b[i],rs) != 0){
        rn = i;
        R = b[rn];
        break;
      }
    }
    Point rt = reflection(l,t);
    if(n == -1 || rn == -1 ||
       containPP(R,rt) == 0){
      cout << "impossible" << endl;
      continue;
    }

    int size = L.size();
    int rsize = R.size();
    int src,dst;
    for(int i = 0 ; i < size ; i++){
      L[i] = reflection(l,L[i]);
    }
    set<Point> st;
    for(int i = 0 ; i < size ; i++){
      if(st.find(L[i]) == st.end()){
        st.insert(L[i]);
      }
    }

    for(int i = 0 ; i < rsize ; i++){
      if(st.find(R[i]) == st.end()){
        st.insert(R[i]);
      }
    }
    s = reflection(l,s);
    t = reflection(l,t);
    if(st.find(s) == st.end()){ st.insert(s); }
    if(st.find(t) == st.end()){ st.insert(t); }
    vector<Point> vec;
    for(auto it = st.begin() ; it != st.end() ; ++it){
      vec.push_back(*it);
    }
    size = vec.size();
    for(int i = 0 ; i < size ; i++){
      for(int j = i+1 ; j < size ; j++){
        Segment seg(vec[i],vec[j]);
        if(containPS(L,seg) && containPS(R,seg)){
          double d = dist(vec[i],vec[j]);
          G[i].push_back(Edge(j,d));
          G[j].push_back(Edge(i,d));
        }
      }
      if(s == vec[i]){ src = i; }
      if(t == vec[i]){ dst = i; }
    }
    double res = dijkstra(src,dst);
    if(res == INF){
      cout << "impossible" << endl;
    }else{
      printf("%.10f\n",res);
    }
  }
  return 0;
}