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 <algorithm>
#include <cstdio>
#include <cassert>
#include <vector>
#include <cstring>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <complex>
using namespace std;
#define REP(i,n) for (int i=0; i<(int)n; ++i)
#define FOR(i,c) for (__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(),(c).end()

#define double long double
const double EPS = 1e-8;
const double INF = 1e9;
const double PI = acos(-1);

typedef complex<double> P;
P pIN() { double x,y; cin >> x >> y; return P(x,y); }
namespace std {
  bool operator<(const P &a, const P &b) {
    return real(a) != real(b) ? real(a) < real(b): imag(a) < imag(b);
  }
}
double cross(const P &a, const P &b) {
  return imag(conj(a)*b);
}
double dot(const P &a, const P &b) {
  return real(conj(a)*b);
}
struct L : vector<P> {
  L(const P &a, const P &b) {
    push_back(a); push_back(b);
  }
  L(){}
  P v() const { return (*this)[1]- (*this)[0]; }
};
typedef vector<P> G;
inline L gline(const G &g, int i) { return L(g[i],g[(i+1)<g.size()?i+1:0]); }

inline int ccw(const L &l, const P &p) {
  P b = l.v(), c = p-l[0];
  if (cross(b,c) > EPS) return 1;
  if (cross(b,c) < -EPS) return -1;
  if (dot(b,c) < -EPS) return 2;
  if (EPS<norm(b) && norm(b) < norm(c)-EPS) return -2;
  return 0;
}
inline int ccw(const L &l, const L &m) { return ccw(l,l[0]+m.v());}
inline int ccw2(const L &l, const P &p) { return abs(ccw(l,p)) == 1? ccw(l,p) : 0; }
inline int ccw2(const L &l, const L &m) { return ccw2(l,l[0]+m.v()); }
inline bool online(const L &l,const P &p) { return !ccw2(l,p); }
inline bool onseg2(const L &s,const P &p) { return ccw(L(s[0],p),s[1]) == -2; }
inline bool onseg(const L &s, const P &p) {
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS; // triangle inequality
}
inline bool sameline(const L &l, const L &m) { return !ccw2(l,m[0]) && !ccw2(l,m[1]); }
inline bool different(const L &l, const L &s) { return ccw2(l,s[0])*ccw2(l,s[1]) <= 0; }
inline bool different2(const L &l, const L &s) { return ccw(l,s[0])*ccw(l,s[1]) == -1; }
P projection(const L &l, const P &p) { return l[0] + dot(p-l[0],l.v()) / norm(l.v()) * l.v(); }
P reflection(const L &l, const P &p) { return p + P(2,0)* (projection(l,p)-p); }
inline bool intersectSS(const L &s, const L &t) { return different(s,t) && different(t,s); }
inline bool intersectSS2(const L &s, const L &t) { 
  return different2(s,t) && different2(t,s);
  // if (sameline(s,t)) return onseg2(s,t[0]) || onseg2(s,t[1]);
  // else return different2(s,t) && different2(t,s);
}
// inline bool intersectLS(const L &l, const L &s) { return different(l,s); }
inline bool intersectLS(const L &l, const L &s) {
  return cross(l[1]-l[0], s[0]-l[0])*       // s[0] is left of l
         cross(l[1]-l[0], s[1]-l[0]) < EPS; // s[1] is right of l
}

P crosspoint(const L &l, const L &m) {
  double A = cross(l.v(), m.v());
  double B = cross(l.v(), l[1]-m[0]);
  if (abs(A) < EPS && abs(B) < EPS) {
    if (onseg(l,m[0])) return m[0];
    double r = -1;
    if (onseg(m,l[0])) r = abs(m[0]-l[0]);
    if (onseg(m,l[1])) {
      double rr = abs(m[0]-l[1]);
      if (r < -EPS || r > rr) {
        rr = r;
      }
    }
    if (r < EPS) return m[1];
    return m[0] + P(r/abs(m[1]-m[0]),0) * (m[1]-m[0]);
  }
  // if (abs(A) < EPS) assert(false);
  return m[0] + B/A*m.v();
}

// #define curr(g, i) g[i]
// #define next(g, i) g[(i+1)%g.size()]
#define curr(g, i) g[i]
#define next(g, i) g[i+1<g.size()?i+1:0]
#define prev(g, i) g[i?i-1:g.size()-1]

int contains(const G &g, const P &p) {
  bool in = 0;
  REP(i,g.size()) {
    P a = g[i] - p;
    P b = next(g,i) - p;
    if (imag(a) > imag(b)) swap(a,b);
    if (imag(a) <= 0 && 0 < imag(b))
      if (cross(a,b) < 0) in = !in;
    if (abs(cross(a,b))< EPS && dot(a,b) <= EPS) return 0;
  }
  return in?1:-1;
}

bool contain4(const G &g, const L &seg) {
  if (contains(g,seg[0]) == -1) return 0;
  if (contains(g,seg[1]) == -1) return 0;
  double len = abs(seg[0]-seg[1]);
  // if (len < EPS) return 1;
  typedef pair<double,int> pdi;
  vector<pdi> t;
  t.push_back(pdi(0,-1));
  t.push_back(pdi(1,-1));
  bool in = 0;
  REP(i,g.size()) {
    const L gl = gline(g,i);
    if (intersectLS(seg,gl)) {
      P cp = crosspoint(gl,seg);
      if (dot(seg[1]-seg[0], cp-seg[0]) < -EPS) {
        if (ccw(seg,gl[0]) == -1 || ccw(seg,gl[1]) == -1) {
          // cout << gl[0] << " " << gl[1] << endl;
          in = !in;
        }
      }
      if (intersectSS(gl, seg)) {
        if (intersectSS2(gl,seg)) return 0;
        t.push_back(pdi(abs(cp-seg[0])/len, i));
      }
    }
  }

  // sort(ALL(v));
  sort(ALL(t));
  // v.erase(unique(ALL(v)),v.end());

  // cout << in << endl;
  // FOR(it, t) cout << it->first << " " << it->second << endl;
  int id = 0;
  REP(i, t.size()-1) {
    P p = seg[0] + (t[i].first+t[i+1].first)/2*(seg[1]-seg[0]);
    double r = (t[i].first+t[i+1].first)/2;
    bool ok = 0;
    if (abs(t[i].first-t[i+1].first)<EPS) continue;
//    cout << "r = " << r << endl;
    while(id<t.size() && t[id].first < r + EPS) {
      int k = t[id].second;
      if (k == -1) {
        id++;
        continue;
      }
      // cout << k << " " << ccw2(seg,g[k]) << " " << ccw2(seg,next(g,k)) << endl;
      // cout << g[k] << "," << g[(k+1)%g.size()] << " " << r << " ; " << p << " " << cross(g[(k+1)%g.size()]-g[k], p-g[k]) << " " << ccw2(seg,next(g,k)) << " " << onseg(gline(g,k),p) << endl;
      
      if (ccw(seg,g[k]) == -1 || ccw(seg,next(g,k)) == -1) {
        in = !in;
      }
      if (onseg(gline(g,k),p)) {
        // cout << g[k] << " " << next(g,k) << " " << p << endl;
        ok = 1;
      }
      id++;
    }
    // cout << p << " " << id << " " << in << " " << ok << endl;
    if (!in && !ok) return 0;
  }
  return 1;
}

bool contain5(const G &g, const L &seg) {
  if (contains(g,seg[0]) == -1) return 0;
  if (contains(g,seg[1]) == -1) return 0;
  double len = abs(seg[0]-seg[1]);
  vector<P> v;
  v.push_back(seg[0]);
  v.push_back(seg[1]);
  REP(i,g.size())
    if (intersectSS(gline(g,i), seg)) {
      if (intersectSS2(gline(g,i),seg)) return 0;
      P cp = crosspoint(gline(g,i),seg);
      v.push_back(cp);
    }
  sort(ALL(v));
  // v.erase(unique(ALL(v)),v.end());
  
  int id = 0;
  REP(i, v.size()-1) {
    P p = (v[i]+v[i+1])*P(0.5,0);
    if (contains(g,p) == -1) return 0;
  }
  return 1;
}



typedef double Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) {}
};
bool operator<(const Edge &e, const Edge &f) {
  return e.weight > f.weight;
}
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
Weight dijkstra(const Graph &g, int s, int t) {
  vector<Weight> dist(g.size(), INF);
  dist[s] = 0;
  priority_queue<Edge> Q;
  for (Q.push(Edge(-2,s,0)); !Q.empty();)  {
    Edge e = Q.top(); Q.pop();
    if (dist[e.dst] < e.weight) continue;
    if (e.dst == t) return dist[t];
    FOR(f,g[e.dst]) {
      if (dist[f->dst] > e.weight +f->weight) {
        dist[f->dst] = e.weight + f->weight;
        Q.push(Edge(f->src, f->dst, e.weight+f->weight));
      }
    }
  }
  return -1;
}
int main() {
  int n;
  while(cin >> n,n) {
    vector<G> vg;
    REP(i,n) {
      G g;
      int m;
      cin  >> m;
      REP(j,m) {
        g.push_back(pIN());
      }
      vg.push_back(g);
    }
    P s(pIN());
    P t(pIN());
    P ss(pIN());
    P tt(pIN());
    L mirror(ss,tt);
    bool hanten[n];
    vector<G> vg2(vg);
    REP(i,n) {
      int c = ccw2(mirror,vg[i][0]);
      assert(c != 0);
      if (c == ccw2(mirror,s)) {        
        hanten[i] = 0;
      }else {
        FOR(it, vg2[i]) {
          *it = reflection(mirror,*it);
        }
        reverse(ALL(vg2[i]));
        hanten[i] = 1;
      }
    }
    P s2 = reflection(mirror,s);
    P t2 = reflection(mirror,t);
    int sid = -1;
    int tid = -1;
    // cout << s << " " << t << endl;
    // REP(i,n) {
    //   FOR(it, vg[i]) {
    //     cout << *it << " ";
    //   }
    //   cout << endl;
    // }
    REP(i,n) {
      // cout << i << " " << contains(vg[i], s) << endl;
      if (contains(vg[i], s) >= 0) sid = i;
      if (contains(vg[i], t) >= 0) tid = i;
    }
    assert(sid == tid && sid != -1);
    int sid2 = -1;
    int tid2 = -1;
    REP(i,n) {
      if (contains(vg[i], s2) >= 0) sid2 = i;
      if (contains(vg[i], t2) >= 0) tid2 = i;
    }
    if (sid2 == -1 || tid2 == -1 || sid2 != tid2) {
      puts("impossible");
      continue;
    }
    vector<P> ps;
    FOR(jt, vg2[sid2]) {
      ps.push_back(*jt);
    }
    REP(i, vg[sid].size()) {
      L l1(vg[sid][i], next(vg[sid],i));
      REP(j,vg2[sid2].size()) {
        L l2(vg2[sid2][i], next(vg2[sid2],i));
        if (intersectSS(l1,l2)) {
          // ps.push_back(crosspoint(l1,l2));
        }
      }
      ps.push_back(vg[sid][i]);
    }
    sort(ALL(ps));
    ps.erase(unique(ALL(ps)), ps.end());
    int start = ps.size();
    ps.push_back(s);
    int dst = ps.size();
    ps.push_back(t);

    Graph g(ps.size());
    // cout << sid2 << endl;
    // FOR(it, vg2[sid2]) {
    //   cout << *it << " ";
    // }
    // cout << endl;
    int cnt = 0;
    REP(i,ps.size()) {
      REP(j,i) {
        L seg(ps[i],ps[j]);
        // cout << seg[0]-P(1,1) << " , " << seg[1]-P(1,1) << endl;
        if (contain4(vg[sid], seg) && contain4(vg2[sid2],seg)) {
          // cout << ps[i]-P(1,1) << " " << ps[j]-P(1,1) << endl;
          g[i].push_back(Edge(i,j,abs(seg.v())));
          g[j].push_back(Edge(j,i,abs(seg.v())));
          cnt++;
        }
      }
    }
    // cout << cnt << endl;
    double ans = dijkstra(g, start, dst);
    if (ans < EPS) {
      puts("impossible");
    } else {
      printf("%.10Lf\n", ans);
    }
  }
}