#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
using namespace std;
const double EPS = 1e-10;
const double INF = 1e+10;
const double PI = acos(-1);
int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
inline double ABS(double a){return max(a,-a);}
struct Pt {
	double x, y;
	Pt() {}
	Pt(double x, double y) : x(x), y(y) {}
	Pt operator+(const Pt &a) const { return Pt(x + a.x, y + a.y); }
	Pt operator-(const Pt &a) const { return Pt(x - a.x, y - a.y); }
	Pt operator*(const Pt &a) const { return Pt(x * a.x - y * a.y, x * a.y + y * a.x); }
	Pt operator-() const { return Pt(-x, -y); }
	Pt operator*(const double &k) const { return Pt(x * k, y * k); }
	Pt operator/(const double &k) const { return Pt(x / k, y / k); }
	bool operator < (const Pt &a)const{
		if(sig(x-a.x))return 0>sig(x-a.x);
		return 0>sig(y-a.y);
	}
	double ABS() const { return sqrt(x * x + y * y); }
	double abs2() const { return x * x + y * y; }
	double arg() const { return atan2(y, x); }
	double dot(const Pt &a) const { return x * a.x + y * a.y; }
	double det(const Pt &a) const { return x * a.y - y * a.x; }
};
bool eq(Pt a,Pt b){
	return sig((a-b).abs2())==0;
}
double tri(const Pt &a, const Pt &b, const Pt &c) { return (b - a).det(c - a); }
int iSP(Pt a, Pt b, Pt c) {
	int s = sig((b - a).det(c - a));
	if (s) return s;
	if (sig((b - a).dot(c - a)) < 0) return -2; // c-a-b
	if (sig((a - b).dot(c - b)) < 0) return +2; // a-b-c
	return 0;
}
Pt pLL(Pt a, Pt b, Pt c, Pt d) {
	b = b - a; d = d - c; return a + b * (c - a).det(d) / b.det(d);
}
int iLL(Pt a, Pt b, Pt c, Pt d) {
	if (sig((b - a).det(d - c))) return 1; // intersect
	if (sig((b - a).det(c - a))) return 0; // parallel
	return -1; // correspond
}
bool iSS(Pt a, Pt b, Pt c, Pt d) {
	return (iSP(a, b, c) * iSP(a, b, d) <= 0 && iSP(c, d, a) * iSP(c, d, b) <= 0);
}
bool iSSstrict(Pt a, Pt b, Pt c, Pt d) {
	return (sig(tri(a, b, c)) * sig(tri(a, b, d)) < 0 && sig(tri(c, d, a)) * sig(tri(c, d, b)) < 0);
}
Pt hLP(Pt a,Pt b,Pt c){
	return pLL(a,b,c,c+(b-a)*Pt(0,1));
}
Pt tLP(Pt a,Pt b,Pt c){
	Pt H=hLP(a,b,c);
	return H+H-c;
}
int sGP(int n, vector<Pt>p, Pt a) {
	int side = -1, i;
	p.push_back(p[0]);
	for (i = 0; i < n; ++i) {
		Pt p0 = p[i] - a, p1 = p[i + 1] - a;
		if (sig(p0.det(p1)) == 0 && sig(p0.dot(p1)) <= 0) return 0;
		if (p0.y > p1.y) swap(p0, p1);
		if (sig(p0.y) <= 0 && 0 < sig(p1.y) && sig(p0.det(p1)) > 0) side = -side;
	}
	return side;
}
vector<Pt>poly[110];
vector<Pt>hb;
double ijk[11000];
int v[11000];
bool iGSstrict(int t, Pt a, Pt b) {
	for(int i=0;i<poly[t].size();i++){
		if(iLL(a,b,poly[t][i],poly[t][(i+1)%poly[t].size()])==-1)continue;
		if(iSSstrict(a,b,poly[t][i],poly[t][(i+1)%poly[t].size()]))return 1;
	}
	vector<Pt>tmp;
	for(int i=0;i<poly[t].size();i++){
		if(iLL(a,b,poly[t][i],poly[t][(i+1)%poly[t].size()])==-1)continue;
		if(iSS(a,b,poly[t][i],poly[t][(i+1)%poly[t].size()])){
			tmp.push_back(pLL(a,b,poly[t][i],poly[t][(i+1)%poly[t].size()]));
		}
	}
	tmp.push_back(a);
	tmp.push_back(b);
	//if(sGP(poly[t].size(),poly[t],(a*0.99999+b*0.00001))==-1)return 1;
	//if(sGP(poly[t].size(),poly[t],(b*0.99999+a*0.00001))==-1)return 1;
	std::sort(tmp.begin(),tmp.end());
	for(int i=1;i<tmp.size();i++){
		Pt M=(tmp[i-1]+tmp[i])/2;
		if(sGP(poly[t].size(),poly[t],M)==-1)return 1;
	}
//	printf("%d (%f %f) -> (%f %f)\n",t,a.x,a.y,b.x,b.y);
	return 0;
}
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<110;i++)poly[i].clear();
		for(int i=0;i<a;i++){
			int b;scanf("%d",&b);
			for(int j=0;j<b;j++){
				double X,Y;
				scanf("%lf%lf",&X,&Y);
				poly[i].push_back(Pt(X,Y));
			}
		}
		double X1,Y1,X2,Y2;
		scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2);
		Pt S1=Pt(X1,Y1);
		Pt G1=Pt(X2,Y2);
		scanf("%lf%lf%lf%lf",&X1,&Y1,&X2,&Y2);
		Pt L1=Pt(X1,Y1);
		Pt L2=Pt(X2,Y2);
		Pt S2=tLP(L1,L2,S1);
		Pt G2=tLP(L1,L2,G1);
		int f1=-1;
		int f2=-1;
		int t1=-1;
		int t2=-1;
		for(int i=0;i<a;i++){
			int n=poly[i].size();
			if(~sGP(n,poly[i],S1))f1=i;
			if(~sGP(n,poly[i],S2))f2=i;
			if(~sGP(n,poly[i],G1))t1=i;
			if(~sGP(n,poly[i],G2))t2=i;
		}
		if(f1==-1||f2==-1||t1==-1||t2==-1||f1!=t1||f2!=t2){
			printf("impossible\n");continue;
		}
		hb.clear();
		for(int i=0;i<poly[f1].size();i++)hb.push_back(poly[f1][i]);
		for(int i=0;i<poly[f2].size();i++)hb.push_back(tLP(L1,L2,poly[f2][i]));
	/*	for(int i=0;i<poly[f1].size();i++){
			for(int j=0;j<poly[f2].size();j++){
				Pt v1=tLP(L1,L2,poly[f2][j]);
				Pt v2=tLP(L1,L2,poly[f2][(j+1)%poly[f2].size()]);
				if(iSSstrict(poly[f1][i],poly[f1][(i+1)%poly[f1].size()],v1,v2)){
					hb.push_back(pLL(poly[f1][i],poly[f1][(i+1)%poly[f1].size()],v1,v2));
				}
			}
		}*/
		int S=hb.size();
		hb.push_back(S1);
		int T=hb.size();
		hb.push_back(G1);
		int sz=hb.size();
		for(int i=0;i<11000;i++){
			ijk[i]=999999999;v[i]=0;
		}
		ijk[S]=0;
	//	for(int i=0;i<sz;i++)printf("%f %f\n",hb[i].x,hb[i].y);
		for(int i=0;i<sz;i++){
			double dist=99999999;
			int at=-1;
			for(int j=0;j<sz;j++){
				if(!v[j]&&ijk[j]<dist){
					dist=ijk[j];
					at=j;
				}
			}
			if(!~at)break;
		//	printf("%f %f: %f\n",hb[at].x,hb[at].y,ijk[at]);
			v[at]=1;
			Pt from1=hb[at];
			Pt from2=tLP(L1,L2,hb[at]);
			for(int j=0;j<sz;j++){
				if(v[j])continue;
				if(ijk[j]<dist+(from1-hb[j]).ABS())continue;
				Pt to1=hb[j];
				Pt to2=tLP(L1,L2,to1);
		//		printf("%f %f %f %f\n",from1.x,from1.y,from2.x,from2.y);
				if(iGSstrict(f1,from1,to1)){
			//		printf("(%f %f) -> (%f %f): hit on 1\n",from1.x,from1.y,to1.x,to1.y);
					continue;
				}
				if(iGSstrict(f2,from2,to2)){
			//		printf("(%f %f) -> (%f %f): hit on 2\n",from1.x,from1.y,to1.x,to1.y);
					continue;
				}
				ijk[j]=dist+(from1-hb[j]).ABS();
			}
		}
		if(ijk[T]>99999999)printf("impossible\n");
		else printf("%.12f\n",ijk[T]);
	}
}

Measured memory_bytes: 1276