#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

using ld = double;
using Point =  complex<ld>;
const ld eps = 1e-9;
const ld pi = acos(-1.0);

bool eq(ld a, ld b) {
	return (abs(a - b) < eps);
}

bool cmp(Point x,Point y){
	if(eq(x.real(),y.real()))return x.imag()<y.imag();
	return x.real()<y.real();
}

bool eqq(Point x,Point y){
	return eq(x.real(),y.real())&&eq(x.imag(),y.imag());
}
//内積
ld dot(Point a, Point b) {
	return real(conj(a)*b);
}
//外積
ld cross(Point a, Point b) {
	return imag(conj(a)*b);
}


//線分
//直線にするなら十分通い２点を端点とすればよい
class Line {
public:
	Point a, b;
};
//円
class Circle {
public:
	Point p;
	ld r;
};
//3点の位置関係
int ccw(Point a, Point b, Point c) {
	b -= a; c -= a;
	if (cross(b, c) > eps)return 1;//a,b,cが反時計回り
	if (cross(b, c) < -eps)return -1;//a,b,cが時計回り
	if (dot(b, c) < 0)return 2;//c,a,bの順に一直線
	if (norm(b) < norm(c))return -2;//a,b,cの順に一直線
	return 0;//a,c,bの順に一直線
}
//2直線の交差判定
bool isis_ll(Line l, Line m) {
	return !eq(cross(l.b - l.a, m.b - m.a), 0);
}
//直線と線分の交差判定
bool isis_ls(Line l, Line s) {
	return (cross(l.b - l.a, s.a - l.a)*cross(l.b - l.a, s.b - l.a) < eps);
}
//点が直線上に存在するか
bool isis_lp(Line l, Point p) {
	return (abs(cross(l.b - p, l.a - p)) < eps);
}
//点が線分上に存在するか
bool isis_sp(Line s, Point p) {
	return (abs(s.a - p) + abs(s.b - p) - abs(s.b - s.a) < eps);
}
//線分と線分の交差判定
bool isis_ss(Line s, Line t) {
    if (isis_sp(t, s.a) || isis_sp(t, s.b))return false;
	if (isis_sp(s, t.a) || isis_sp(s, t.b) )return true;
	return(cross(s.b - s.a, t.a - s.a)*cross(s.b - s.a, t.b - s.a) < -eps && cross(t.b - t.a, s.a - t.a)*cross(t.b - t.a, s.b - t.a) < -eps);
}
//点から直線への垂線の足
Point proj(Line l, Point p) {
	ld t = dot(p - l.a, l.a - l.b) / norm(l.a - l.b);
	return l.a + t * (l.a - l.b);
}

Point cont(Line l, Point p){
	return 2.0*proj(l, p) - p;
}

//直線と直線の交点
//平行な２直線に対しては使うな！！！！
Point is_ll(Line s, Line t) {
	Point sv = s.b - s.a; Point tv = t.b - t.a;
	return s.a + sv * cross(tv, t.a - s.a) / cross(tv, sv);
}
//直線と点の距離
ld dist_lp(Line l, Point p) {
	return abs(p - proj(l, p));
}
//直線と直線の距離
ld dist_ll(Line l, Line m) {
	return isis_ll(l, m) ? 0 : dist_lp(l, m.a);
}
//線分と直線の距離
ld dist_ls(Line l, Line s) {
	return isis_ls(l, s) ? 0 : min(dist_lp(l, s.a), dist_lp(l, s.b));
}
//線分と点の距離
ld dist_sp(Line s, Point p) {
	Point r = proj(s, p);
	return isis_sp(s, r) ? abs(p - r) : min(abs(p - s.a), abs(p - s.b));
}
//線分と線分の距離
ld dist_ss(Line s, Line t) {
	if (isis_ss(s, t))return 0;
	return min({ dist_sp(s,t.a),dist_sp(s,t.b),dist_sp(t,s.a),dist_sp(t,s.b) });
}

bool included(vector<Point> pol, Point p){
    int n=pol.size();
    ld sum=0;
    rep(i,n){
        Point cur=pol[i], nxt=pol[(i+1)%n];
        if(isis_sp({cur,nxt},p))return true;
        sum+=arg((nxt-p)/(cur-p));
    }
    return abs(sum)>1;
}

void solve(int n){
    vector<vector<Point>> pols(n);
    rep(i,n){
        int m;
        cin>>m;
        rep(j,m){
            int x,y;
            cin>>x>>y;
            pols[i].push_back(Point(x,y));
        }
    }
    Point s,t;
    int x,y;
    cin>>x>>y;
    s = Point(x,y);
    cin>>x>>y;
    t = Point(x,y);
    Line l;
    cin>>x>>y;
    l.a = Point(x,y);
    cin>>x>>y;
    l.b = Point(x,y);
    vector<Point> front,back;
    rep(i,n){
        if(isis_ls(l,{s,pols[i][0]})){
            rep(j,pols[i].size())pols[i][j]=cont(l, pols[i][j]);
            if(included(pols[i],s)&&included(pols[i],t))back=pols[i];
        }
        else if(included(pols[i],s)&&included(pols[i],t))front=pols[i];
    }
    reverse(back.begin(),back.end());
    if(front.size()==0||back.size()==0){
        cout<<"impossible"<<endl;
        return ;
    }

    vector<Point> points;
    for(auto p : front)points.push_back(p);
    for(auto p : back)points.push_back(p);
    points.push_back(s);points.push_back(t);
    n = points.size();
    int f = front.size(), b=back.size();
    vector<pair<int,ld>> v[n];
    rep(i,n){
        if(!included(back,points[i])||!included(front,points[i]))continue;
        rep(j,i){
            if(!included(back,points[j])||!included(front,points[j]))continue;
            Line seg = Line{points[i],points[j]};
            bool ok=true;
            rep(k,f){
                if(isis_ss(seg, {front[k], front[(k+1)%f]}))ok=false;
            }
            rep(k,b){
                if(isis_ss(seg, {back[k], back[(k+1)%b]}))ok=false;
            }
            Point mid = (points[i]+points[j])*.5;
            if(!included(front, mid)||!included(back, mid))ok=false;
            if(ok)v[i].emplace_back(j,abs(points[i]-points[j]));
            if(ok)v[j].emplace_back(i,abs(points[i]-points[j]));
        }
    }
    vector<ld> dist(n,inf);
    dist[f+b]=0;
    using Pa = pair<ld,int>;
    priority_queue<Pa,vector<Pa>,greater<Pa>> que;
    que.push({0,f+b});
    while(que.size()){
        auto pa = que.top();que.pop();
        ld d=pa.first;int cur=pa.second;
        if(dist[cur]+eps<d)continue;
        for(auto to : v[cur]){
            if(dist[to.first]>dist[cur]+to.second){
                dist[to.first]=dist[cur]+to.second;
                que.emplace(dist[to.first], to.first);
            }
        }
    }
    if(dist[f+b+1]>1e9)cout<<"impossible"<<endl;
    else cout<<dist[f+b+1]<<endl;
}

int main(){
    int n;
    cout<<fixed<<setprecision(10);
    while(cin>>n,n!=0)solve(n);
    return 0;
}
