Problem: Convex polygon pillar industrial city

The Industrial Convex Pillar City (ICPC) is a city of buildings in the shape of several convex polygonal columns. You are about to walk through this city from your current location S to your destination T. The sun is strong today, so I want to go to my destination without passing through the sun as much as possible. If the building is on a straight line connecting the point where you are standing and the sun, you are behind the building and will not be exposed to the sun. Also, since all the outer circumferences of the buildings in this city have eaves, while walking along the outer circumference of the buildings, even if you walk along the edge of the sun, you will not receive the sunlight. You are free to walk around the city anywhere except inside the building.

Create a program that outputs the walking distance of Hinata when walking from the current location to the destination so as not to receive the sun.

<image>

Figure E1: For the first input

<image>

Figure E2: For the second input

<image>

Figure E3: For the third input

Input

The input consists of multiple datasets. The maximum number of data sets does not exceed 30. Each dataset is represented in the following format.

> N
> NV1 H1 X1,1 Y1,1 X1,2 Y1,2 ... X1, NV1 Y1, NV1
> ...
> NVN HN XN, 1 YN, 1 XN, 2 YN, 2 ... XN, NVN YN, NVN
> θ φ
> Sx Sy Tx Ty
>

N in the first line represents the number of buildings. The following N lines specify the shape of each building. NVi represents the number of vertices of the polygon when the i-th building is viewed from above, and Hi represents the height of the i-th building. Xi, j and Yi, j represent the x-coordinate and y-coordinate of the j-th vertex of the polygon when the i-th building is viewed from above. The vertices are given in counterclockwise order. All buildings are convex polygons when viewed from above, and there are no other buildings inside the building, and the vertices and sides do not overlap with other polygons. The following lines are given θ and φ, which represent the direction of the sun, θ represents the direction of the sun as a counterclockwise angle from the positive direction of x, and φ is the elevation angle of the sun from the horizon, that is, looking up at the sun. It represents the angle between the direction of the line of sight and the ground surface. However, the sun is at infinity and does not change its position during movement. The following lines are given the coordinates of the current location and destination, (Sx, Sy) and (Tx, Ty).

> All the numerical values ​​given by the input are integers and satisfy the following conditions.

> 1 ≤ N ≤ 100
> 3 ≤ NVi ≤ 12
> 1 ≤ Hi ≤ 1,000
> 0 ≤ θ <360
> 0 <φ <90

All coordinates are -1,000 or more and 1,000 or less. The current location and the destination are different, and neither exists inside or outside the building.

> The end of the input is represented by a single zero line.

> ### Output

For each dataset, output the shortest walking distance in Hinata on one line. The output must not have an absolute error greater than 0.001.

> ### Sample Input


2
4 1 0 0 1 0 1 1 0 1
4 2 2 2 3 2 3 3 2 3
60 45
-1 -1 4 4
Four
4 1 0 0 3 1 1 2 0 1
3 2 10 7 8 2 12 4
6 8 7 12 8 13 9 15 10 19 11 24 10 25
5 4 16 2 16 4 12 8 14 2 15 0
167 38
3 3 15 21
12
4 3 -8 -3 -9 -3 -9 -5 -8 -6
4 5 -4 -5 -7 -5 -7 -6 -5 -6
4 2 -4 1 -5 1 -5 -4 -4 -4 -4
4 1 -1 1 -2 1 -2 -4 -1 -3
4 2 2 3 -1 3 -2 2 3 2
4 1 3 1 2 1 2 -3 3 -4
4 7 1 0 0 0 0 -1 1 -1
4 4 9 5 7 5 7 4 10 4
4 3 6 5 5 4 5 0 6 0
4 5 8 -1 5 -1 6 -2 8 -2
4 1 10 0 9 0 9 -2 10 -1
4 6 10 2 8 2 8 1 10 1
131 78
-10 10 10 -10
0


Output for Sample Input


1.93185
7.87174
20.86840





Example

Input

2
4 1 0 0 1 0 1 1 0 1
4 2 2 2 3 2 3 3 2 3
60 45
-1 -1 4 4
4
4 1 0 0 3 1 1 2 0 1
3 2 10 7 8 2 12 4
6 8 7 12 8 13 9 15 10 19 11 24 10 25
5 4 16 2 16 4 12 8 14 2 15 0
167 38
3 3 15 21
12
4 3 -8 -3 -9 -3 -9 -5 -8 -6
4 5 -4 -5 -7 -5 -7 -6 -5 -6
4 2 -4 1 -5 1 -5 -4 -4 -4
4 1 -1 1 -2 1 -2 -4 -1 -3
4 2 2 3 -1 3 -2 2 3 2
4 1 3 1 2 1 2 -3 3 -4
4 7 1 0 0 0 0 -1 1 -1
4 4 9 5 7 5 7 4 10 4
4 3 6 5 5 4 5 0 6 0
4 5 8 -1 5 -1 6 -2 8 -2
4 1 10 0 9 0 9 -2 10 -1
4 6 10 2 8 2 8 1 10 1
131 78
-10 10 10 -10
0


Output

1.93185
7.87174
20.86840

Solution (in CPP):

Solution:
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <vector>
#include <utility>
#include <queue>
#define inf 1e18
#define eps 1e-9

using namespace std;

struct vec2d{
	double x, y;
	vec2d(){}
	vec2d(double x, double y){
		this->x = x, this->y = y;
	}
	double add(double a, double b){
		if(fabs(a+b) < eps * (fabs(a) + fabs(b))) return 0.0;
		return a+b;
	}
	vec2d operator+(vec2d ope){
		return vec2d(add(x, ope.x), add(y, ope.y));
	}
	vec2d operator-(vec2d ope){
		return vec2d(add(x, -ope.x), add(y, -ope.y));
	}
	vec2d operator*(double t){
		return vec2d(x*t, y*t);
	}
	vec2d operator/(double t){
		return vec2d(x/t, y/t);
	}
	double dot(vec2d ope){
		return add(x*ope.x, y*ope.y);
	}
	double cross(vec2d ope){
		return add(x*ope.y, -y*ope.x);
	}
	double norm(){
		double d2 = dot(*this);
		if(d2 > 0) return sqrt(d2);
		return 0.0;
	}
};

double distPP(vec2d p, vec2d q){
	return (p-q).norm();
}

double distSP(vec2d p, vec2d q, vec2d x)
{
	if((x-p).dot(q-p) <= 0) return distPP(p, x);
	if((x-q).dot(p-q) <= 0) return distPP(q, x);
	return fabs( (x-p).cross(q-p) / distPP(p, q) );
}

bool isOnS(vec2d p, vec2d q, vec2d x)
{
	return (p-x).cross(q-x) == 0 && (p-x).dot(q-x) <= 0;
}

bool isCross(vec2d p, vec2d q, vec2d r, vec2d s)
{
	if((q-p).cross(s-r) == 0){
		return isOnS(p, q, r) || isOnS(p, q, s) || isOnS(r, s, p) || isOnS(r, s, q);	
	}
	double t = (r-p).cross(s-r) / (q-p).cross(s-r);
	vec2d x = p + (q-p)*t;
	return isOnS(p, q, x) && isOnS(r, s, x);
}

double distSS(vec2d p, vec2d q, vec2d r, vec2d s)
{
	if(isCross(p, q, r, s)) return 0;
	double ret = distSP(p, q, r);
	ret = min(ret, distSP(p, q, s));
	ret = min(ret, distSP(r, s, p));
	ret = min(ret, distSP(r, s, q));
	return ret;
}

bool isInTriangle(vec2d p, vec2d q, vec2d r, vec2d x)
{
	p = p - r, q = q - r, x = x - r;
	double s = p.cross(x) / p.cross(q), t = x.cross(q) / p.cross(q);
	return s >= -eps && t >= -eps && s+t <= 1 + eps;
}

typedef pair<vec2d, vec2d> Segment;
struct Region{
	Segment seg[4];
	Region(){};
	Region(Segment a, Segment b, Segment c, Segment d){
		seg[0] = a, seg[1] = b, seg[2] = c, seg[3] = d;
	}
};

struct edge{
	int to;
	double cost;
	edge(){}
	edge(int a, double b){
		to = a, cost = b;
	}
};

int N;
double h[105];
vector<vec2d> poly[105];
double th, phy;
vec2d s, t;

int S, T, V;
vector<Region> vec;
vector<edge> G[1500];
double dist[1500];

typedef pair<double, int> P;

void dijkstra()
{
	for(int i = 0; i < V; i++) dist[i] = inf;
	dist[S] = 0;
	
	priority_queue< P, vector<P>, greater<P> > Q;
	Q.push( make_pair(0, S) );
	
	int v; double d;
	while(Q.size()){
		d = Q.top().first;
		v = Q.top().second;
		Q.pop();
		if(dist[v] < d) continue;
		for(int i = 0; i < G[v].size(); i++){
			if(dist[G[v][i].to] > d + G[v][i].cost){
				dist[G[v][i].to] = d + G[v][i].cost;
				Q.push( make_pair(dist[G[v][i].to], G[v][i].to) );
			}
		}
	}
}

int main(void)
{
	while(1){
		cin >> N;
		if(N == 0) break;
		
		int n; vec2d tmp;
		for(int i = 0; i < N; i++){
			cin >> n >> h[i];
			poly[i].clear();
			for(int j = 0; j < n; j++){
				cin >> tmp.x >> tmp.y;
				poly[i].push_back(tmp);
			}
		}
		cin >> th >> phy;
		th *= M_PI / 180, phy *= M_PI / 180;
		cin >> s.x >> s.y;
		cin >> t.x >> t.y;
		
		vec.clear();
		for(int i = 0; i < N; i++){
			vec2d a, b, a2, b2;
			for(int j = 0; j < poly[i].size(); j++){
				a = poly[i][j], b = poly[i][(j+1)%(poly[i].size())];
				double l = h[i] / tan(phy);
				a2 = vec2d(a.x - l*cos(th), a.y - l*sin(th));
				b2 = vec2d(b.x - l*cos(th), b.y - l*sin(th));
				vec.push_back(Region(make_pair(a, a2), make_pair(a2, b2), make_pair(b2, b), make_pair(b, a)));
			}
		}
		V = vec.size();
		
		for(int i = 0; i < V; i++) G[i].clear();
		for(int i = 0; i < V; i++){
			for(int j = 0; j < V; j++){
				if(i >= j) continue;
				double dist = inf;
				for(int k = 0; k < 4; k++){
					for(int l = 0; l < 4; l++){
						dist = min(dist, distSS(vec[i].seg[k].first, vec[i].seg[k].second,
							vec[j].seg[l].first, vec[j].seg[l].second));
					}
				}
				G[i].push_back(edge(j, dist));
				G[j].push_back(edge(i, dist));
			}
		}
		
		S = V, T = V+1;
		G[S].clear(), G[T].clear();
		for(int i = 0; i < V; i++){
			double dist = inf;
			if(isInTriangle(vec[i].seg[0].first, vec[i].seg[1].first, vec[i].seg[2].first, s)
			|| isInTriangle(vec[i].seg[0].first, vec[i].seg[2].first, vec[i].seg[3].first, s)){
				dist = 0;
			}
			else{
				for(int j = 0; j < 4; j++){
					dist = min(dist, distSP(vec[i].seg[j].first, vec[i].seg[j].second, s));
				}
			}
			G[S].push_back(edge(i, dist));
			G[i].push_back(edge(S, dist));
		}
		for(int i = 0; i < V; i++){
			double dist = inf;
			if(isInTriangle(vec[i].seg[0].first, vec[i].seg[1].first, vec[i].seg[2].first, t)
			|| isInTriangle(vec[i].seg[0].first, vec[i].seg[2].first, vec[i].seg[3].first, t)){
				dist = 0;
			}
			else{
				for(int j = 0; j < 4; j++){
					dist = min(dist, distSP(vec[i].seg[j].first, vec[i].seg[j].second, t));
				}
			}
			G[T].push_back(edge(i, dist));
			G[i].push_back(edge(T, dist));
		}
		V += 2;
		
		dijkstra();
		
		//for(int i = 0; i < V; i++) cout << dist[i] << " "; cout << endl;
		double ans = min(dist[T], distPP(s, t));
		printf("%.11f\n", ans);
	}
	
	return 0;
}