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<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]);
	}
}