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 <iostream>
#include <complex>
#include <cstdio>
#include <utility>
#include <vector>
#include <queue>
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
typedef vector<P> Poly;
#define X real()
#define Y imag()
#define EPS (1e-10)
#define INF (1e15)

namespace std{
  bool operator<(const P& a, const P& b){
    return a.X != b.X ? a.X < b.X : a.Y < b.Y;
  }
  bool cmp_y(const P &a, const P &b){
    return a.Y != b.Y ? a.Y < b.Y : a.X < b.X;
  }
}

double dot(P a, P b){
  return a.X * b.X + a.Y * b.Y;
}
double cross(P a, P b){
  return a.X * b.Y - a.Y * b.X;
}

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( abs(b) + EPS < abs(c) ) return -2;
  return 0;
}

bool is_cross(L a, L b){
  if(ccw(a.first,a.second,b.first)*ccw(a.first,a.second,b.second) < 0 &&
     ccw(b.first,b.second,a.first)*ccw(b.first,b.second,a.second) < 0) return true;
  return false;
}

P projection(P a, P b){
  //ベクトルaにのベクトルbに対する正射影ベクトル
  return dot(a, b)/abs(b)/abs(b)*b;
}

P line_symmetry(L l, P p){
  //点pと直線lに対して線対称な点
  return p + (l.first - p + projection(p-l.first,l.second-l.first))*2.0;
}

int in_poly(P a, Poly p){
  int n = p.size(), c = 0;
  p.push_back(p[0]);
  for(int i = 0; i < n; ++i){
    P s = p[i]-a, t = p[i+1]-a;
    if(!ccw(s,t,P(0,0))) return 1;//辺上
    if(s.Y > t.Y + EPS) swap(s,t);
    if((s.Y*t.Y < -EPS || (s.Y*t.Y < EPS && t.Y > EPS)) && cross(s,t) < EPS) ++c;
  }
  if(c%2) return 2;//内部
  return 0;//外部
}

double dijkstra(vector< vector<double> > &G){
  int n = G.size();
  vector<double> d(n,INF);
  priority_queue< pair<double,int> > wait;
  wait.push(make_pair(0,0));
  while(!wait.empty()){
    double dist = -wait.top().first;
    int v = wait.top().second;
    wait.pop();
    if(d[v] <= dist) continue;
    d[v] = dist;
    for(int i = 0; i < n; ++i){
      if(dist + G[v][i] < d[i]){
        wait.push(make_pair(-dist - G[v][i],i));
      }
    }
  }
  return d[1];
}

vector< vector<double> > make_graph(P start, P goal, Poly q, Poly p){
  int n = p.size() + q.size() + 2;
  vector< vector<double> > G(n, vector<double>(n,INF));

  Poly S;
  S.push_back(start);
  S.push_back(goal);
  for(int i = 0; i < q.size(); ++i) S.push_back(q[i]);
  for(int i = 0; i < p.size(); ++i) S.push_back(p[i]);
  /*
  for(int i = 0; i < n; ++i)
    cout << S[i] << endl;
  */
  vector<L> E;
  for(int i = 0; i < q.size(); ++i)
    E.push_back(make_pair(q[i],q[(i+1)%q.size()]));
  for(int i = 0; i < p.size(); ++i)
    E.push_back(make_pair(p[i],p[(i+1)%p.size()]));

  for(int i = 0; i < n; ++i){
    for(int j = i; j < n; ++j){
      if(in_poly((S[i]+S[j])/2.0,q) && in_poly((S[i]+S[j])/2.0,p)){
        bool f = true;
        for(int k = 0; k < E.size(); ++k){
          if((ccw(S[i],S[j],E[k].first) == 0 && abs(S[i]-E[k].first) > EPS && abs(S[j]-E[k].first) > EPS) ||
             (ccw(S[i],S[j],E[k].second) == 0 && abs(S[i]-E[k].second) > EPS && abs(S[j]-E[k].second) > EPS)){
            f = false;
            break;
          }
          if(is_cross(L(S[i],S[j]),E[k])){
            f = false;
            break;
          }
        }
        if(f){
          G[i][j] = abs(S[i]-S[j]);
          G[j][i] = G[i][j];
        }
      }
    }
  }
  return G;
}

int main(){
  int N, M;
  while(cin >> N, N){
    double x, y;
    vector<Poly> polys(N);
    for(int i = 0; i < N; ++i){
      cin >> M;
      for(int j = 0; j < M; ++j){
        cin >> x >> y;
        polys[i].push_back(P(x,y));
      }
    }
    cin >> x >> y;
    P start(x,y);
    cin >> x >> y;
    P goal(x,y);
    double x_, y_;
    cin >> x >> y >> x_ >> y_;
    L l(P(x,y),P(x_,y_));
    P start_ = line_symmetry(l,start);;
    Poly p, q;
    bool f = false, g = false;
    for(int i = 0; i < N; ++i){
      if(in_poly(start,polys[i])){
        p = polys[i];
        f = true;
      }
      if(in_poly(start_,polys[i])){
        q = polys[i];
        g = true;
      }
    }
    if(!(f&&g)){
      cout << "impossible" << endl;
      continue;
    }
    for(int i = 0; i < q.size(); ++i){
      q[i] = line_symmetry(l,q[i]);
    }
    vector< vector<double> > G = make_graph(start,goal,q,p);

    /*
    for(int i = 0; i < G.size(); ++i){
      for(int j = 0; j < G.size(); ++j){
        if(G[i][j] >= INF) cout << " INF  | ";
        else printf("%.3f | ",G[i][j]);
      }cout << endl;
    }
    */
    double ans = dijkstra(G);
    if(ans >= INF) cout << "impossible" << endl;
    else printf("%.12f\n",ans);
  }
  return 0;
}