#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;
}

Measured memory_bytes: 1520