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 <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <complex>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << (x) << endl;


#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 1010

typedef double P_type;
typedef complex<P_type> P;
const P_type P_eps = 1e-8; //??´??°???????????????

namespace std{
  template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
  }
};


P rotate(P p, double theta){
  return p * P(cos(theta), sin(theta));
}

//??????
double dot(P a, P b) {
  return (a * conj(b)).real();
}

//??????
double cross(P a, P b) {
  return (a * conj(b)).imag();
}

//???????¨???????
int ccw(P a, P b, P c){
  if(cross(b-a,c-a) > P_eps) return 1; //COUNTER_CLOCKWISE
  if(cross(b-a,c-a) < -P_eps) return -1; //CLOCKWISE
  if(dot(b-a,c-a) < P_eps) return -2; //c -> a -> b
  if(dot(a-b,c-b) < P_eps) return 2; //a -> b -> c
  return 0; //a -> c -> b
}

/* ??????ab??¨???c????????¢ */
double distanceSP(P a, P b, P c) {
  if ( dot(b-a, c-a) < P_eps ) return abs(c-a);
  if ( dot(a-b, c-b) < P_eps ) return abs(c-b);
  return abs(cross(b-a, c-a)) / abs(b-a);
}

bool iscontained(vector<P> &g, P p){
  int n = g.size();
  bool f = false;
  for(int i=0;i<n;i++){
    P a = g[i] - p, b = g[(i+1)%n] - p;
    if(abs(cross(a,b)) < P_eps && dot(a,b) < P_eps) return true;
    if(a.imag() > b.imag()) swap(a,b);
    if(a.imag() < P_eps && P_eps < b.imag() && cross(a,b) > P_eps) f = !f;
  }
  return f;
}

/* ConvexHull(??????) */

vector<P> ConvexHull(vector<P> s){
  vector<P> g;
  int n = (int)s.size();
  
  if(n<3) return s;
  
  sort(s.begin(),s.end());
  
  for(int i=0;i<n;i++){
    for(int m = (int)g.size();m>=2 && ccw(g[m-2],g[m-1],s[i]) != -1; m--){
      g.pop_back();
    }
    g.push_back(s[i]);
  }
  
  int t = (int)g.size();
  
  for(int i=n-2;i>=0;i--){
    for(int m = (int)g.size();m>t && ccw(g[m-2],g[m-1],s[i]) != -1; m--){
      g.pop_back();
    }
    g.push_back(s[i]);
  }
  
  reverse(g.begin(),g.end());
  g.pop_back();
  
  return g;
}


bool solve(){  
  int n;
  int h[SIZE];
  int theta, phi;
  int sx,sy,gx,gy;
  vector<P> shade[1000];
  vector<P> points[1000];
  
  scanf("%d",&n);
  
  if(n == 0) return false;
  
  for(int i=0;i<n;i++){
    int nv;
    scanf("%d%d",&nv,h+i);
    
    for(int j=0;j<nv;j++){
      int x,y;
      scanf("%d%d",&x,&y);
      points[i].push_back(P(x,y));
    }
  }

  scanf("%d%d",&theta, &phi);
  scanf("%d%d%d%d",&sx,&sy,&gx,&gy);

  P start(sx,sy), goal(gx,gy);
  
  for(int i=0;i<n;i++){

    double dist_sa = h[i] / tan(phi / 180.0 * M_PI); 
    P sa = P(cos((theta + 180) / 180.0 * M_PI), sin((theta + 180) / 180.0 * M_PI));
    sa *= dist_sa;
    
    int m = points[i].size();
    
    for(int j=0;j<m;j++){

      P sp = sa + points[i][j];
      
      points[i].push_back(sp);
    }
  }
  
  for(int i=0;i<n;i++){
    shade[i] = ConvexHull(points[i]);
  }
  shade[n].push_back(start);
  shade[n+1].push_back(goal);
  
  double dist[SIZE][SIZE];

  for(int i=0;i<n+2;i++){
    for(int j=0;j<n+2;j++){
      dist[i][j] = 1e18;
    }
  }
  
  for(int i=0;i<n+2;i++){
    int m = shade[i].size();

    for(int j=0;j<n+2;j++){
      for(int k=0;k<shade[i].size();k++){
        for(int l=0;l<shade[j].size();l++){
          double res = distanceSP(shade[i][k],shade[i][(k+1)%m],shade[j][l]);
          dist[i][j] = dist[j][i] = min(dist[j][i],res);
        }
      } 
    }
  }

  for(int i=0;i<n+2;i++){
    for(int j=0;j<n+2;j++){
      for(int k=0;k<shade[j].size();k++){
        if(iscontained(shade[i],shade[j][k])){
          dist[j][i] = dist[i][j] = 0;
        }
      }
    }
  }

  for(int k=0;k<n+2;k++){
    for(int i=0;i<n+2;i++){
      for(int j=0;j<n+2;j++){
        dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
      }
    }
  }

  printf("%.10lf\n",dist[n][n+1]);
  
  return true;
}

int main(){
  
  while(solve());
  
  return 0;
}