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

Source: aizu | Difficulty: UNKNOWN_DIFFICULTY


Solutions:
from math import sin, cos, tan, radians
from heapq import heappush, heappop
import sys
readline = sys.stdin.readline
write = sys.stdout.write

def dot3(O, A, B):
	(ox, oy) = O
	(ax, ay) = A
	(bx, by) = B
	return (ax - ox) * (bx - ox) + (ay - oy) * (by - oy)

def cross3(O, A, B):
	(ox, oy) = O
	(ax, ay) = A
	(bx, by) = B
	return (ax - ox) * (by - oy) - (bx - ox) * (ay - oy)

def dist2(A, B):
	(ax, ay) = A
	(bx, by) = B
	return (ax - bx) ** 2 + (ay - by) ** 2

def is_intersection(P0, P1, Q0, Q1):
	C0 = cross3(P0, P1, Q0)
	C1 = cross3(P0, P1, Q1)
	if C0 == C1 == 0:
		E0 = dot3(P0, P1, Q0)
		E1 = dot3(P0, P1, Q1)
		if not E0 < E1:
			(E0, E1) = (E1, E0)
		return E0 <= dist2(P0, P1) and 0 <= E1
	D0 = cross3(Q0, Q1, P0)
	D1 = cross3(Q0, Q1, P1)
	return C0 * C1 <= 0 and D0 * D1 <= 0

def convex_hull(ps):
	qs = []
	n = len(ps)
	for p in ps:
		while len(qs) > 1 and cross3(qs[-1], qs[-2], p) >= 0:
			qs.pop()
		qs.append(p)
	t = len(qs)
	for i in range(n - 2, -1, -1):
		p = ps[i]
		while len(qs) > t and cross3(qs[-1], qs[-2], p) >= 0:
			qs.pop()
		qs.append(p)
	return qs

def cross2(p, q):
	return p[0] * q[1] - p[1] * q[0]

def dot2(p, q):
	return p[0] * q[0] + p[1] * q[1]

def dist1(p):
	return p[0] ** 2 + p[1] ** 2

def segment_line_dist_d(x, p0, p1):
	z0 = (p1[0] - p0[0], p1[1] - p0[1])
	z1 = (x[0] - p0[0], x[1] - p0[1])
	if 0 <= dot2(z0, z1) <= dist1(z0):
		return cross2(z0, z1) ** 2 / dist1(z0)
	z2 = (x[0] - p1[0], x[1] - p1[1])
	return min(dist1(z1), dist1(z2))

def polygon_contain(x, ps):
	if len(ps) == 1:
		return 0
	pl = len(ps)
	return all((cross3(ps[i - 1], ps[i], x) > 0 for i in range(pl))) or all((cross3(ps[i - 1], ps[i], x) < 0 for i in range(pl)))

def convex_polygon_contain(p0, qs):
	L = len(qs)
	if L < 3:
		return False
	left = 1
	right = L
	(x0, y0) = q0 = qs[0]
	while left + 1 < right:
		mid = left + right >> 1
		if cross3(q0, p0, qs[mid]) <= 0:
			left = mid
		else:
			right = mid
	if left == L - 1:
		left -= 1
	qi = qs[left]
	qj = qs[left + 1]
	v0 = cross3(q0, qi, qj)
	v1 = cross3(q0, p0, qj)
	v2 = cross3(q0, qi, p0)
	if v0 < 0:
		v1 = -v1
		v2 = -v2
	return 0 <= v1 and 0 <= v2 and (v1 + v2 <= v0)

def convex_polygons_intersection(ps, qs):
	pl = len(ps)
	ql = len(qs)
	if pl == 1 or ql == 1:
		return 0
	i = j = 0
	while (i < pl or j < ql) and i < 2 * pl and (j < 2 * ql):
		(px0, py0) = ps0 = ps[(i - 1) % pl]
		(px1, py1) = ps1 = ps[i % pl]
		(qx0, qy0) = qs0 = qs[(j - 1) % ql]
		(qx1, qy1) = qs1 = qs[j % ql]
		if is_intersection(ps0, ps1, qs0, qs1):
			return 1
		ax = px1 - px0
		ay = py1 - py0
		bx = qx1 - qx0
		by = qy1 - qy0
		v = ax * by - bx * ay
		va = cross3(qs0, qs1, ps1)
		vb = cross3(ps0, ps1, qs1)
		if v == 0 and va < 0 and (vb < 0):
			return 0
		if v == 0 and va == 0 and (vb == 0):
			i += 1
		elif v >= 0:
			if vb > 0:
				i += 1
			else:
				j += 1
		elif va > 0:
			j += 1
		else:
			i += 1
	return 0

def find_tangent(p0, qs):
	L = len(qs)
	d = L // 3
	gx = (qs[0][0] + qs[d][0] + qs[2 * d][0]) / 3
	gy = (qs[0][1] + qs[d][1] + qs[2 * d][1]) / 3
	g = (gx, gy)
	ma = -1
	mi = 2
	k0 = 0
	k1 = 0
	for i in range(L):
		v = cross3(p0, qs[i], g) / (dist2(p0, g) * dist2(p0, qs[i])) ** 0.5
		if v > ma:
			k1 = i
			ma = v
		if v < mi:
			k0 = i
			mi = v
	return (k0, k1)

def tangent_polygon_dist(ps, qs):
	Lp = len(ps)
	Lq = len(qs)
	(pi, qi) = find_tangent(qs[0], ps)
	(pj, qj) = find_tangent(ps[0], qs)
	if qi < pi:
		qi += Lp
	if qj < pj:
		qj += Lq
	res = dist2(ps[pi], qs[pj])
	if pj < qj:
		for i in range(pi, qi + 1):
			x = ps[i - Lp]
			for j in range(pj, qj + 1):
				res = min(res, segment_line_dist_d(x, qs[(j - 1) % Lq], qs[j - Lq]))
	if pi < qi:
		for j in range(pj, qj + 1):
			x = qs[j - Lq]
			for i in range(pi, qi + 1):
				res = min(res, segment_line_dist_d(x, ps[(i - 1) % Lp], ps[i - Lp]))
	return res ** 0.5

def polygons_dist(ps, qs):
	if convex_polygons_intersection(ps, qs) or convex_polygon_contain(ps[0], qs) or convex_polygon_contain(qs[0], ps):
		return 0
	return tangent_polygon_dist(ps, qs)

def solve():
	N = int(readline())
	if N == 0:
		return False
	P = [[] for i in range(N)]
	H = [0] * N
	for i in range(N):
		(k, h, *ps) = map(int, readline().split())
		H[i] = h
		Pi = P[i]
		for j in range(k):
			(x, y) = ps[2 * j:2 * j + 2]
			Pi.append((x, y))
	(theta, phi) = map(int, readline().split())
	r_theta = radians(theta)
	r_phi = radians(90 - phi)
	dx = -cos(r_theta) * tan(r_phi)
	dy = -sin(r_theta) * tan(r_phi)
	(sx, sy, tx, ty) = map(int, readline().split())
	for i in range(N):
		Pi = P[i]
		hi = H[i]
		for j in range(len(Pi)):
			(x, y) = Pi[j]
			Pi.append((x + hi * dx, y + hi * dy))
		Pi.sort()
		P[i] = convex_hull(Pi)[:-1]
	P.append([(sx, sy)])
	P.append([(tx, ty)])
	E = [[0] * (N + 2) for i in range(N + 2)]
	dist = [10 ** 18] * (N + 2)
	for i in range(N + 2):
		for j in range(i + 1, N + 2):
			E[i][j] = E[j][i] = polygons_dist(P[i], P[j])
	que = [(0, N)]
	dist[N] = 0
	while que:
		(cost, v) = heappop(que)
		if dist[v] < cost:
			continue
		for w in range(N + 2):
			n_cost = cost + E[v][w]
			if n_cost < dist[w]:
				dist[w] = n_cost
				heappush(que, (n_cost, w))
	print('%.16f' % dist[N + 1])
	return True
while solve():
	...