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 <bits/stdc++.h>
using namespace std;
const double PI = acos(-1);
const double INF = 100000000;
struct point{
  double x, y;
  point(){
    x = 0;
    y = 0;
  }
  point(double x, double y): x(x), y(y){
  }
  point operator +(point P){
    return point(x + P.x, y + P.y);
  }
  point operator -(point P){
    return point(x - P.x, y - P.y);
  }
  point operator /(double k){
    return point(x / k, y / k);
  }
};
double abs(point P){
  return sqrt(pow(P.x, 2) + pow(P.y, 2));
}
double dot(point P, point Q){
  return P.x * Q.x + P.y * Q.y;
}
double cross(point P, point Q){
  return P.x * Q.y - P.y * Q.x;
}
double point_distance(point P, point Q){
  return abs(Q - P);
}
struct line{
  point A, B;
  line(){
  }
  line(point A, point B): A(A), B(B){
  }
  
};
point vec(line L){
  return L.B - L.A;
}
double point_line_distance(point P, line L){
  return abs(cross(L.B - L.A, P - L.A)) / abs(vec(L));
}
double point_segment_distance(point P, line L){
  if (dot(L.B - L.A, P - L.A) < 0){
    return point_distance(P, L.A);
  } else if (dot(L.A - L.B, P - L.B) < 0){
    return point_distance(P, L.B);
  } else {
    return point_line_distance(P, L);
  }
}
vector<point> sort_polygon(vector<point> &P){
  int sz = P.size();
  point G;
  for (int i = 0; i < sz; i++){
    G = G + P[i];
  }
  G = G / sz;
  vector<pair<double, int>> P2(sz);
  for (int i = 0; i < sz; i++){
    P2[i] = make_pair(atan2(P[i].y - G.y, P[i].x - G.x), i);
  }
  sort(P2.begin(), P2.end());
  vector<point> ans(sz);
  for (int i = 0; i < sz; i++){
    ans[i] = P[P2[i].second];
  }
  return ans;
}
bool point_in_triangle(point X, point A, point B, point C){
  vector<point> P = {A, B, C};
  sort_polygon(P);
  point tmp = P[0];
  P.push_back(tmp);
  for (int i = 0; i < 3; i++){
    if (cross(P[i + 1] - P[i], X - P[i]) < 0){
      return false;
    }
  }
  return true;
}
vector<point> convex_hull(vector<point> P){
  int sz = P.size();
  point G;
  for (int i = 0; i < sz; i++){
    G = G + P[i];
  }
  G = G / sz;
  while (1){
    sz = P.size();
    bool upd = false;
    point tmp = P[0];
    point tmp2 = P[1];
    P.push_back(tmp);
    P.push_back(tmp2);
    vector<point> Q;
    for (int i = 1; i <= sz; i++){
      if (!point_in_triangle(P[i], G, P[i - 1], P[i + 1])){
        Q.push_back(P[i]);
      } else {
        upd = true;
      }
    }
    if (upd){
      swap(P, Q);
    } else {
      return Q;
    }
  }
}
bool point_in_polygon(point X, vector<point> P){
  int sz = P.size();
  point tmp = P[0];
  P.push_back(tmp);
  for (int i = 0; i < sz; i++){
    if (cross(P[i + 1] - P[i], X - P[i]) < 0){
      return false;
    }
  }
  return true;
}
double point_polygon_distance(point X, vector<point> P){
  int sz = P.size();
  if (point_in_polygon(X, P)){
    return 0;
  }
  point tmp = P[0];
  P.push_back(tmp);
  double ans = INF;
  for (int i = 0; i < sz; i++){
    ans = min(ans, point_segment_distance(X, line(P[i], P[i + 1])));
  }
  return ans;
}
double polygon_distance(vector<point> P, vector<point> Q){
  int szP = P.size();
  int szQ = Q.size();
  for (int i = 0; i < szP; i++){
    if (point_in_polygon(P[i], Q)){
      return 0;
    }
  }
  for (int i = 0; i < szQ; i++){
    if (point_in_polygon(Q[i], P)){
      return 0;
    }
  }
  point tmpP = P[0];
  P.push_back(tmpP);
  point tmpQ = Q[0];
  Q.push_back(tmpQ);
  double ans = INF;
  for (int i = 0; i < szP; i++){
    for (int j = 0; j < szQ; j++){
      ans = min(ans, point_segment_distance(P[i], line(Q[j], Q[j + 1])));
    }
  }
  for (int i = 0; i < szQ; i++){
    for (int j = 0; j < szP; j++){
      ans = min(ans, point_segment_distance(Q[i], line(P[j], P[j + 1])));
    }
  }
  return ans;
}
int main(){
  cout << fixed << setprecision(5);
  while (1){
    int N;
    cin >> N;
    if (N == 0){
      break;
    }
    vector<double> H(N);
    vector<vector<point>> V(N);
    for (int i = 0; i < N; i++){
      int NV;
      cin >> NV;
      cin >> H[i];
      V[i] = vector<point>(NV);
      for (int j = 0; j < NV; j++){
        cin >> V[i][j].x >> V[i][j].y;
      }
    }
    double theta, phi;
    cin >> theta >> phi;
    theta = theta / 180 * PI;
    phi = phi / 180 * PI;
    point S;
    cin >> S.x >> S.y;
    point T;
    cin >> T.x >> T.y;
    vector<vector<point>> V2(N + 2);
    for (int i = 0; i < N; i++){
      int NV = V[i].size();
      point d;
      d.x = H[i] / tan(phi) * cos(theta) * -1;
      d.y = H[i] / tan(phi) * sin(theta) * -1;
      for (int j = 0; j < NV; j++){
        V2[i].push_back(V[i][j]);
        V2[i].push_back(V[i][j] + d);
      }
      V2[i] = sort_polygon(V2[i]);
      V2[i] = convex_hull(V2[i]);
    }
    V2[N].push_back(S);
    V2[N + 1].push_back(T);
    vector<vector<double>> d(N + 2, vector<double>(N + 2, INF));
    for (int i = 0; i < N + 2; i++){
      d[i][i] = 0;
      for (int j = i + 1; j < N + 2; j++){
        if (i < N){
          if (j < N){
            d[i][j] = polygon_distance(V2[i], V2[j]);
          } else {
            d[i][j] = point_polygon_distance(V2[j][0], V2[i]);
          }
        } else {
          d[i][j] = point_distance(V2[i][0], V2[j][0]);
        }
        d[j][i] = d[i][j];
      }
    }
    for (int i = 0; i < N + 2; i++){
      for (int j = 0; j < N + 2; j++){
        for (int k = 0; k < N + 2; k++){
          d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
        }
      }
    }
    cout << d[N][N + 1] << endl;
  }
}