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;

#define dump(a) cerr << #a << " " << a << endl
#define rep(i,n) for(int i = 0; i < (n); i++)
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
using ll = long long;
using vi = vector<int>;

const double EPS = 1e-8;
const double inf = 1e12;

using P = complex<double>;
namespace std{
  bool operator < (const P &a, const P &b){
    return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
  }
  bool isnan(const P &p){
    return isnan(real(p)) or isnan(imag(p));
  }
}
double cross(const P &p, const P &q){
  return imag(conj(p)*q);
}
double dot(const P &p, const P &q){
  return real(conj(p)*q);
}
struct L : public vector<P>{
  L(const P &p, const P &q){
    push_back(p);
    push_back(q);
  }
};
using G = vector<P>;

int ccw(P a,P b, P c){
  b -= a; c -= a;
  if(cross(b,c)>0) return 1;
  if(cross(b,c)<0) return -1;
  if(dot(b,c)<0) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}


double intersectSP(const L &s, const P &p){
  return abs(s[0]-p)+abs(s[1]-p)-abs(s[1]-s[0]) < EPS;
}
double intersectSS(const L &s, const L &t){
  if(ccw(s[0],s[1],t[0])*ccw(s[0],s[1],t[1]) <= 0 &&
     ccw(t[0],t[1],s[0])*ccw(t[0],t[1],s[1]) <= 0) return true;
  if(intersectSP(s,t[0]) or intersectSP(s,t[1]) or
     intersectSP(t,s[0]) or intersectSP(t,s[1])) return true;
  return false;
}

P projection(const L &l, const P &p){
  double t = dot(p-l[0],l[0]-l[1]) / norm(l[0]-l[1]);
  return l[0] + t*(l[0]-l[1]);
}
double distanceSP(const L&s, const P &p){
  const P r = projection(s,p);
  if(intersectSP(s,r)) return abs(r-p);
  return min(abs(s[0]-p),abs(s[1]-p));
}
double distanceSS(const L &s, const L &t){
  if(intersectSS(s,t)) return 0;
  return min(min(distanceSP(s,t[0]),distanceSP(s,t[1])),
	     min(distanceSP(t,s[0]),distanceSP(t,s[1])));
}
double distanceGP(const G &g, const P &p){
  int n = g.size();
  double ans = inf;
  rep(i,n){
    L l(g[i],g[(i+1)%n]);
    ans = min(ans, distanceSP(l,p));
  }
  return ans;
}
double distanceGG(const G &g, const G &h){
  double ans = inf;
  int n = g.size(), m = h.size();
  rep(i,g.size()) rep(j,h.size()){
    L l1(g[i],g[(i+1)%n]), l2(h[j],h[(j+1)%m]);
    ans = min(ans, distanceSS(l1,l2));
  }
  return ans;
}

vector<P> convex_hull(vector<P> ps){
  int n = ps.size(), k = 0;
  sort(ps.begin(),ps.end());
  vector<P> ch(2*n);
  for(int i = 0; i < n; ch[k++] = ps[i++])
    while(k >= 2 and ccw(ch[k-2],ch[k-1],ps[i]) <= 0) --k;
  for(int i = n-2, t = k+1; i >= 0; ch[k++] = ps[i--])
    while(k >= t and ccw(ch[k-2],ch[k-1],ps[i]) <= 0) --k;
  ch.resize(k-1);
  return ch;
}

bool containGP(const G &g, const P &p){
  double sum = 0;
  int n = g.size();
  rep(i,n){
    int j = (i+1)%n;
    if(intersectSP(L(g[i],g[j]-g[i]),p))
      return true;
    sum += arg((g[j]-p)/(g[i]-p));
  }
  return abs(sum) > 1;
}

using Cost = double;
class node{
public:
  int v;
  Cost d;
  node(int a_, Cost b_):v(a_),d(b_){}
  bool operator <(const node &n) const { return d > n.d; }
};
class edge{
public:
  int to;
  Cost d;
  edge(){}
  edge(int to_, Cost d_) : to(to_), d(d_) {}
};
class dijkstra{
public:
  vector<vector<edge>> G;
  vector<Cost> dist;
  
  dijkstra(int s, const vector<vector<edge>> &G_):G(G_){
    dist.resize(G.size(),inf);

    priority_queue<node> que;
    que.push(node(s,0));
    dist[s] = 0;

    while(!que.empty()){
      int v = que.top().v;
      Cost d = que.top().d;
      que.pop();

      rep(i,G[v].size()){
	Cost tmp = d + G[v][i].d;
	if(dist[G[v][i].to] > tmp + EPS){
	  dist[G[v][i].to] = tmp;
	  que.push(node(G[v][i].to, tmp));
	}
      }
    }
  }
};

int main(){
  int n;
  while(cin >> n,n){
    vector<G> gs(n);
    vi hs(n);
    rep(i,n){
      int nv; cin >> nv;
      cin >> hs[i];
      rep(j,nv){
	double x, y; cin >> x >> y;
	gs[i].push_back(P(x,y));
      }
    }
    int inttheta; cin >> inttheta;
    double theta = double(inttheta) * M_PI / 180;
    if(inttheta <= 180){
      theta -= M_PI;
    }else{
      theta -= M_PI;
    }
    double phi; cin >> phi;
    phi *= M_PI / 180;
    P s, t;
    double x, y; cin >> x >> y;
    s = P(x, y);
    cin >> x >> y;
    t = P(x, y);

    rep(i,n){
      P diff = polar(hs[i]/tan(phi),theta);
      int m = gs[i].size();
      rep(j,m){
	gs[i].push_back(gs[i][j]+diff);
      }
      gs[i] = convex_hull(gs[i]);
    }

    vector<vector<edge>> g(n+2);
    rep(i,n){
      double d;
      if(containGP(gs[i],s)) d = 0;
      else d = distanceGP(gs[i],s);
      g[i].emplace_back(n,d);
      g[n].emplace_back(i,d);
    }
    rep(i,n){
      double d;
      if(containGP(gs[i],t)) d = 0;
      else d = distanceGP(gs[i],t);
      g[i].emplace_back(n+1,d);
      g[n+1].emplace_back(i,d);
    }
    rep(i,n) FOR(j,i+1,n){
      double d = distanceGG(gs[i],gs[j]);
      g[i].emplace_back(j,d);
      g[j].emplace_back(i,d);
    }
    double d = abs(s-t);
    g[n].emplace_back(n+1,d);
    g[n+1].emplace_back(n,d);
    dijkstra dijk(n, g);
    printf("%.10lf\n", dijk.dist[n+1]);
  }
}