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 <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <deque>
#include <complex>
#include <stack>
#include <queue>
#include <cstdio>
#include <cctype>
#include <cstring>
#include <ctime>
#include <iterator>
#include <bitset>
#include <numeric>
#include <list>
#include <iomanip>
using namespace std;


typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;

typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;

#define VV(T) vector<vector< T > >

template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}

template <class F, class T>
void convert(const F &f, T &t){
	stringstream ss;
	ss << f;
	ss >> t;
}


#define REP(i,n) for(int i=0;i<int(n);++i)
#define ALL(v) (v).begin(),(v).end()
#define RALL(v) (v).rbegin(),(v).rend()
#define PB push_back
#define ITR ::iterator


#define MOD 1000000009LL
#define EPS 1e-8

typedef double D;
typedef complex<D> P;
typedef const P &rP;
typedef vector<P> polygon;
typedef const polygon &rpolygon;

typedef pair<D,int> pdi;

inline D dot(rP a, rP b){
	return real(a) * real(b) + imag(a) * imag(b);
}

inline D cross(rP a, rP b){
	return real(a) * imag(b) - imag(a) * real(b);
}

inline int ccw(rP a, P b, P c) {
	b -= a;
	c -= a;
	D cr = cross(b, c);
	if (cr > EPS){ return +1; }	// counter clockwise
	if (cr < -EPS){ return -1; }	// clockwise
	if (dot(b, c) < -EPS){ return +2; }	// c--a--b on line
	if (abs(b) + EPS < abs(c)){ return -2; }	// a--b--c on line
	return 0;
}

D distanceLP(rP a, rP b, rP c){
	return abs(cross(b - a, c - a)) / abs(b - a);
}

D distanceLsP(rP a, rP b, rP c){
	if( dot(b - a, c - a) <= 0.0 ) return abs(c - a);
	if( dot(a - b, c - b) <= 0.0 ) return abs(c - b);
	return distanceLP(a, b, c);
}

bool containsPlgP(rpolygon plg, rP pt){
	int cnt = 0;
	D y = imag(pt);
	for(int i = 0; i < plg.size(); ++i){
		int j = (i + 1 == plg.size() ? 0: i + 1);
		if( distanceLsP(plg[i], plg[j], pt) <= EPS ){
			return true;
		}
		D dyi = imag(plg[i]) - y;
		D dyj = y - imag(plg[j]);
		D tx = (dyi * real(plg[j]) + dyj * real(plg[i])) / (dyi + dyj);
		if(imag(plg[i]) >= y && imag(plg[j]) < y){
			if( tx < real(pt) ) ++cnt;
		}
		else if(imag(plg[i]) < y && imag(plg[j]) >= y){
			if( tx < real(pt) ) ++cnt;
		}
	}
	return (cnt % 2 != 0);
}

D divrat(rP pa1, rP pa2, rP pb1, rP pb2){
	P da12 = pa2 - pa1;
	P db21 = pb1 - pb2;
	P dab1 = pb1 - pa1;
	D d = cross(da12, db21);
	if(abs(d) > EPS){
		D t = cross(dab1, db21) / d;
		D s = cross(da12, dab1) / d;
		
		if((-EPS < t && t < 1.0 + EPS) && (-EPS < s && s < 1.0 + EPS)){
			return t;	//前半は交点が線分1に含まれるか、後半は線分2に含まれるかどうか
		}
	}
	return DBL_MAX;
}

bool containsPlgS(rpolygon plg, rP a, rP b){
	int n = plg.size();
	vector<D> r(2);
	r[1] = 1.0;
	P dif = b - a;
	for(int i = 0; i < n; ++i){
		D t = divrat(a, b, plg[i], plg[(i + 1) % n]);
		if(t < DBL_MAX){ r.push_back(t); }
	}
	sort(ALL(r));
	for(int i = 1; i < r.size(); ++i){
		if(!containsPlgP(plg, a + 0.5 * (r[i] + r[i - 1]) * dif)){
			return false;
		}
	}
	return true;
}


P input(){
	D x, y;
	scanf("%lf%lf", &x, &y);
	return P(x, y);
}

void mirror(rP pl1, rP pl2, P &p){
	P d = pl2 - pl1;
	d /= abs(d);
	P a = pl1 - p;
	a -= dot(a, d) * d;
	p += 2.0 * a;
}

D solve(int n){
	int m;
	P ps, pg, pl1, pl2;
	vector<polygon> blds(n), plgs;
	plgs.reserve(5);
	for(int i = 0; i < n; ++i){
		scanf("%d", &m);
		blds[i].resize(m);
		for(int j = 0; j < m; ++j){
			blds[i][j] = input();
		}
	}
	ps = input();
	pg = input();
	pl1 = input();
	pl2 = input();

	if(ccw(pl1, pl2, ps) == -1){
		swap(pl1, pl2);
	}

	for(int i = 0; i < n; ++i){
		if(ccw(pl1, pl2, blds[i][0]) == -1){
			for(int j = 0; j < blds[i].size(); ++j){
				mirror(pl1, pl2, blds[i][j]);
			}
		}

		if(containsPlgP(blds[i], ps) || containsPlgP(blds[i], pg)){
			plgs.push_back(blds[i]);
		}
	}
	if(plgs.size() != 2){ return DBL_MAX; }
	
	vector<P> pts;
	pts.push_back(ps);
	pts.push_back(pg);
	for(int i = 0; i < 2; ++i){
		pts.insert(pts.end(), ALL(plgs[i]));
	}
	
	vector<vector<pdi> > G(pts.size());
	for(int i = 1; i < pts.size(); ++i)
	for(int j = 0; j < i; ++j){
		bool ok = true;
		for(int k = 0; k < 2; ++k){
			if(!containsPlgS(plgs[k], pts[i], pts[j])){
				ok = false;
				break;
			}
		}
		if(ok){
			D ds = abs(pts[i] - pts[j]);
			G[i].push_back(pdi(ds, j));
			G[j].push_back(pdi(ds, i));
		}
	}
	
	vector<D> d(pts.size(), DBL_MAX);
	d[0] = 0.0;
	priority_queue<pdi,vector<pdi>,greater<pdi> > pq;
	pq.push(pdi());
	while(!pq.empty()){
		D a = pq.top().first;
		int u = pq.top().second;
		pq.pop();
		if(d[u] != a){ continue; }

		for(int i = 0; i < G[u].size(); ++i){
			D b = a + G[u][i].first;
			int v = G[u][i].second;
			if(d[v] > b){
				d[v] = b;
				pq.push(pdi(b, v));
			}
		}
	}
	
	return d[1];
}


int main(){
	int n;
	while(scanf("%d", &n), n){
		D ans = solve(n);
		if(ans < DBL_MAX){
			printf("%.15f\n", ans);
		}
		else{
			puts("impossible");
		}
	}
}