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 <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;
typedef vector<P> Pol;
D eps=1e-9,inf=1e9;
int A,n[100];
Pol pol[100];
P s,t;
L l;
bool eq(D a,D b){return abs(a-b)<eps;}
int sig(D a){return eq(a,0)?0:(a>0?1:-1);}
D cro(P a,P b){return imag(conj(a)*b);}
D dot(P a,P b){return real(conj(a)*b);}
int ccw(P a,P b,P c){
	if(sig(cro(b-a,c-a))==1) return 1;
	if(sig(cro(b-a,c-a))==-1) return -1;
	if(eq(abs(a-c)+abs(c-b),abs(a-b))) return 0;
	if(eq(abs(a-b)+abs(c-b),abs(a-c))) return -2;
	return 2;
}
int ccw(L a,P p){return ccw(a.fs,a.sc,p);}
P intLL(L a,L b){
	D t=cro(a.sc-a.fs,a.sc-b.fs)/cro(a.sc-a.fs,b.sc-b.fs);
	return b.fs+t*(b.sc-b.fs);
}
bool contain(Pol pol,P p){
	bool in=0;
	int N=pol.size();
	rep(i,N){
		P a=pol[i]-p,b=pol[(i+1)%N]-p;
		if(ccw(a,b,P(0,0))==0) return 1;
		if(imag(a)>imag(b)) swap(a,b);
		if(sig(imag(a))<=0&&0<sig(imag(b))&&ccw(P(0,0),a,b)==1) in=!in;
	}
	return in;
}
P perp(L l,P p){
	D t=dot(p-l.fs,l.fs-l.sc)/norm(l.fs-l.sc);
	return l.fs+t*(l.fs-l.sc);
}
P refl(L l,P p){
	return p+2.0*(perp(l,p)-p);
}
bool ispal(L a,L b){
	return sig(cro(a.fs-a.sc,b.fs-b.sc))==0;
}
bool iSS(L a,L b){
	return ccw(a,b.fs)*ccw(a,b.sc)<=0&&ccw(b,a.fs)*ccw(b,a.sc)<=0;
}
L BL;
bool compBL(const P& a,const P& b){			//BL?????????????????????(BL.fs??´????°???????)
	return dot(l.sc-l.fs,a-l.fs)<dot(l.sc-l.fs,b-l.fs);
}
bool containE(Pol pol,L l){
	vector<P> ps;
	ps.pb(l.fs);
	ps.pb(l.sc);
	int N=pol.size();
	rep(i,N){
		L a(pol[i],pol[(i+1)%N]);
		if(ispal(a,l)) continue;
		if(!ispal(a,l)&&iSS(a,l)) ps.pb(intLL(a,l));
	}
	BL=l;
	sort(all(ps),compBL);
	int K=ps.size();
	rep(i,K-1) ps.pb((ps[i]+ps[i+1])/2.0);
	for(P p:ps) if(!contain(pol,p)) return 0;
	return 1;
}
int main(){
	while(true){
		cin>>A;
		if(A==0) break;
		rep(i,A){
			pol[i].clear();
			cin>>n[i];
			rep(j,n[i]){
				int x,y;
				cin>>x>>y;
				pol[i].pb(P(x,y));
			}
		}
		{
			int a,b,c,d;
			cin>>a>>b>>c>>d;
			s=P(a,b),t=P(c,d);
			cin>>a>>b>>c>>d;
			l=L(P(a,b),P(c,d));
		}
		int a=-1,b=-1,c=-1,d=-1;
		rep(i,A){
			if(contain(pol[i],s)) a=i;
			if(contain(pol[i],t)) b=i;
			if(contain(pol[i],refl(l,s))) c=i;
			if(contain(pol[i],refl(l,t))) d=i;
		}
		if(a<0||b<0||c<0||d<0||a!=b||c!=d){
			puts("impossible");
			continue;
		}
		Pol e=pol[a],f=pol[c];
		int E=e.size(),F=f.size();
		rep(i,F/2) swap(f[i],f[F-1-i]);
		rep(i,F) f[i]=refl(l,f[i]);
		Pol ps;
		ps.pb(s);
		ps.pb(t);
		for(P p:e) ps.pb(p);
		for(P p:f) ps.pb(p);
		int N=ps.size();
		D dis[102][102]={};
		rep(i,N) rep(j,N) if(i!=j){
			dis[i][j]=inf;
			if(containE(e,L(ps[i],ps[j]))&&containE(f,L(ps[i],ps[j]))) dis[i][j]=abs(ps[i]-ps[j]);
		}
		rep(i,N) rep(j,N) rep(k,N) chmin(dis[j][k],dis[j][i]+dis[i][k]);
		if(dis[0][1]==inf) puts("impossible");
		else printf("%.12f\n",dis[0][1]);
	}
}