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 <cstdio>
#include <cassert>
#include <cstring>
#include <vector>
#include <valarray>
#include <array>
#include <queue>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <complex>
#include <random>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;

typedef long double R;
typedef complex<R> P;

const R EPS = 1e-10;
const R PI = acos((R)(-1));

/*
 -1 -> neg
  0 -> near 0
  1 -> pos
  */
int sgn(R a) {
    if (a < -EPS) return -1;
    if (a > EPS) return 1;
    return 0;
}

/*
 -1 -> a > b
 0 -> a near b
 1 -> a < b
 */
int sgn(R a, R b) {
    return sgn(b-a);
}

bool near(const P &a, const P &b) {
    return !sgn(abs(a-b));
}

bool lessP(const P &l, const P &r) {
    if (sgn(l.real(), r.real())) return l.real() < r.real();
    if (sgn(l.imag(), r.imag())) return l.imag() < r.imag();
    return false;
}

R cross(P a, P b) { return a.real()*b.imag() - a.imag()*b.real(); }
R dot(P a, P b) { return a.real()*b.real() + a.imag()*b.imag(); }

/* 1->cclock
  -1->clock
   0->on
   2->back
  -2->front
  */
int ccw(P a, P b, P c) {
    assert(!near(a, b));
    if (near(a, c) || near(b, c)) return 0;
    int s = sgn(cross(b-a, c-a));
    if (s) return s;
    if (dot(b-a, c-a) < 0) return 2;
    if (dot(a-b, c-b) < 0) return -2;
    return 0;
}

R ssqrt(R d) {
    d = max<R>(0, d);
    return sqrt(d);
}

R sacos(R d) {
    d = max<R>(-1, d);
    d = min<R>(1, d);
    return acos(d);
}

struct L {
    P x, y;
    L() {}
    L(P x, P y) :x(x), y(y) {}
};

P vec(const L &l) {
    return l.y - l.x;
}

R abs(const L &l) {
    return abs(vec(l));
}

R arg(const L &l) {
    return arg(vec(l));
}

//??????????????¢??????
R deg2rad(R x) {
    return x/180*PI;
}

//????????¢????????????
R rad2deg(R x) {
    return x/PI*180;
}

//?§???????[0, 2*PI)???
R radNorP(R x) {
    return fmod(fmod(x, 2*PI) + 2*PI, 2*PI);
}

//?§???????[-PI, PI)???
R radNorN(R x) {
    x = radNorP(x);
    if (x >= PI) x -= 2*PI;
    return x;
}

/**
 * radian??§???x???[l, r]?????\??£????????????????????\??????
 * 0:OFF
 * 1:IN
 * 2:ON
 */
bool inR(R l, R r, R x) {
    l = radNorP(l);
    r = radNorP(r);
    x = radNorP(x);
    if (!sgn(l, x) || !sgn(r, x)) return 2;
    if (!sgn(l, r)) return 0;
    if (sgn(l, r) == 1) {
        if (sgn(l, x) == 1 && sgn(x, r) == 1) return 1;
    } else {
        if (sgn(x, r) == 1 || sgn(l, x) == 1) return 1;
    }
    return 0;
}

R distLP(const L &l, const P &p) {
    return abs(cross(vec(l), p-l.x)/abs(vec(l)));
}

int crossLL(const L &l, const L &m, P &r) {
    L mm = L(m.x - l.x, m.y - l.x);
    mm.x *= polar<R>(1.0, -arg(l));
    mm.y *= polar<R>(1.0, -arg(l));
    if (sgn(vec(mm).imag()) == 0) {
        r = l.x;
        if (sgn(mm.x.imag()) == 0) return -1;
        return 0;
    }
    r = mm.x - vec(mm) * (mm.x.imag() / vec(mm).imag());
    r *= polar<R>(1.0, arg(l));
    r += l.x;
    return 1;
}

int crossSS(const L &l, const L &m, P &r) {
    int u = crossLL(l, m, r);
    if (u == 0) return 0;
    if (u == -1) {
        int x = ccw(l.x, l.y, m.x);
        int y = ccw(l.x, l.y, m.y);
        if (x == 0) {
            r = m.x;
            return -1;
        }
        if (y == 0) {
            r = m.y;
            return -1;
        }
        if (x == y) return 0;
        r = l.x;
        return -1;
    }
    if (ccw(l.x, l.y, r) == 0 && ccw(m.x, m.y, r) == 0) return 1;
    return 0;
}

struct T {
    P d[3];
    T() {}
    T(P x, P y, P z) {
        d[0] = x; d[1] = y; d[2] = z;
    }
    P& operator[](int p) {
        return d[p];
    }
    const P& operator[](int p) const {
        return d[p];
    }
    int size() const {
        return 3;
    }
};

typedef vector<P> Pol;

P cu(const T &t, int i) {
    return t[(i%3+3)%3];
}

P cu(const Pol &p, int i) { 
    int s = p.size();
    return p[(i%s+s)%s];
};


//0:P is out 1:P is on line 2:P is in
int contains(const Pol &pol, P p) {
    int in = -1;
    for (int i = 0; i < (int)pol.size(); i++) {
        P a=cu(pol,i)-p, b=cu(pol,i+1)-p;
        if (ccw(a, b, P(0, 0)) == 0) return 1;
        if (imag(a) > imag(b)) swap(a, b);
        if (imag(a) <= 0 && 0 < imag(b)) {
            if (cross(a, b) < 0) in *= -1;
        }
    }
    return in+1;
}

R area(const Pol &p) {
    R u = 0;
    for (int i = 0; i < (int)p.size(); i++) {
        u += cross(cu(p,i), cu(p,i+1));
    }
    return abs(u)/2;
}



//0:P is out 1:P is on line 2:P is in
int contains(const Pol &pol, const L &l) {
    vector<P> v;
    v.push_back(l.x); v.push_back(l.y);
    for (int i = 0; i < (int)pol.size(); i++) {
        P a = cu(pol, i), b = cu(pol, i+1);
        P p;
        if (crossSS(L(a, b), l, p)) {
            v.push_back(p);
        }
    }

    sort(v.begin(), v.end(), [&](const P &x, const P &y){
        return abs(l.x-x) < abs(l.x-y);
    });

    int sz = (int)v.size();
    for (int i = 0; i < sz-1; i++) {
        v.push_back((v[i]+v[i+1])/(R)2);
    }
    bool f = false;
    for (P p: v) {
        int u = contains(pol, p); 
        if (!u) return 0;
        if (u == 2) f = true;
    }
    if (f) return 2;
    return 1;
}


P s, g;
L l;
Pol lp, rp;

P mirror(P p) {
    if (ccw(l.x, l.y, p) == 1) {
        return p + polar(2*distLP(l, p), arg(l)-PI/2);
    } else {        
        return p + polar(2*distLP(l, p), arg(l)+PI/2);
    }
}


R di[110][110];
bool solve() {
    int n;
    cin >> n;
    if (!n) return false;

    Pol p[110];
    for (int i = 0; i < n; i++) {
        int m;
        cin >> m;
        for (int j = 0; j < m; j++) {
            R x, y;
            cin >> x >> y;
            p[i].push_back(P(x, y));
        }
    }

    R sx, sy, gx, gy;
    cin >> sx >> sy >> gx >> gy;
    s = P(sx, sy); g = P(gx, gy);
    R lx1, ly1, lx2, ly2;
    cin >> lx1 >> ly1 >> lx2 >> ly2;
    l = L(P(lx1, ly1), P(lx2, ly2));

    bool f = false;
    for (int i = 0; i < n; i++) {
        if (contains(p[i], s)) {
            if (!contains(p[i], g)) {
                cout << "impossible" << endl;
                return true;
            }
            f = true;
            lp = p[i];
        }
    }
    if (!f) {
        cout << "impossible" << endl;
        return true;
    }

    f = false;
    for (int i = 0; i < n; i++) {
        if (contains(p[i], mirror(s))) {
            if (!contains(p[i], mirror(g))) {
                cout << "impossible" << endl;
                return true;
            }
            f = true;
            rp = p[i];
        }
    }
    if (!f) {
        cout << "impossible" << endl;
        return true;
    }

    vector<P> v;
    v.push_back(s); v.push_back(g);

    for (P p: lp) v.push_back(p);
    for (P p: rp) v.push_back(mirror(p));

    int m = v.size();

    for (int i = 0; i < m; i++) {
        for (int j = i+1; j < m; j++) {
            //cross
            if (near(v[i], v[j])) {
                di[i][j] = di[j][i] = 0;
                continue;
            }
            di[i][j] = di[j][i] = 1e9;
//            cout << "str " << v[i] << " " << v[j] << endl;
//            cout << "str " << mirror(v[i]) << " " << mirror(v[j]) << endl;
            if (!contains(lp, L(v[i], v[j]))) continue;
            if (!contains(rp, L(mirror(v[i]), mirror(v[j])))) continue;
//            cout << "end" << endl;
            di[i][j] = di[j][i] = abs(v[i]-v[j]);
        }
    }

    for (int i = 0; i < m; i++) {
        di[i][i] = 0;
    }

    for (int k = 0; k < m; k++) {
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < m; j++) {
                di[i][j] = min(di[i][j], di[i][k]+di[k][j]);
            }
        }
    }

    if (1e9/2 <= di[0][1]) {
        cout << "impossible" << endl;
        return true;
    }
    printf("%.20Lf\n", di[0][1]);
    return true;
}

int main() {
    while (solve()) {}
    return 0;
}