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>
#include<complex>

using namespace std;

#define rep(i,n) for(int i = 0; i<(n); ++i)
#define reps(i,a,n) for(int i = (a); i<(n); ++i)


#define X real()
#define Y imag()
#define at(i) ((*this)[i])
#define SELF (*this)
enum {TRUE = 1, FALSE = 0, BORDER = -1};
typedef int BOOL;
typedef double R;
const R INF = 1e8;
R EPS = 1e-12;
const R PI = 3.1415926535897932384626;
inline int sig(const R &x) { return (abs(x) < EPS ? 0 : x > 0 ? 1 : -1); }
inline BOOL less(const R &x, const R &y) {return sig(x-y) ? x < y : BORDER;}
typedef complex<R> P;
inline R norm(const P &p){return p.X*p.X+p.Y*p.Y;}
inline R inp(const P& a, const P& b){return (conj(a)*b).X;}
inline R outp(const P& a, const P& b){return (conj(a)*b).Y;}
inline P unit(const P& p){return p/abs(p);}
inline P proj(const P &s, const P &t){return t*inp(s, t)/norm(t);}
inline int ccw(const P &s, const P &t, const P &p, int adv=0){
int res = sig(outp(t-s, p-s));
if(res || !adv) return res;
if(sig(inp(t-s, p-s)) < 0) return -2; // p-s-t
if(sig(inp(s-t, p-t)) < 0) return 2; // s-t-p
return 0; // s-p-t
}
struct L : public vector<P>{ // line
L(const P &p1, const P &p2){this->push_back(p1);this->push_back(p2);}
L(){}
P dir()const {return at(1) - at(0);}
BOOL online(const P &p)const {return !sig(outp(p-at(0), dir()));}
};
struct S : public L{ // segment
S(const P &p1, const P &p2):L(p1, p2){}
S(){}
BOOL online(const P &p)const {
if(!sig(norm(p - at(0))) || !sig(norm(p - at(1)))) return BORDER;
// 座標の二乗とEPS の差が大きすぎないように注意
return !sig(outp(p-at(0), dir())) && inp(p-at(0), dir()) > EPS && inp(p-at(1),
-dir()) > -EPS;
//return !sig(abs(at(0)-p) + abs(at(1) - p) - abs(at(0) - at(1)));
}
};
// 射影と反射 (s を t に)
inline P proj(const P &s, const L &t){return t[0] + proj(s-t[0], t[1]-t[0]);}
inline P reflect(const P &s, const L &t){return (R)2.*proj(s, t) - s;}
inline S reflect(const S &s, const L &t){return S(reflect(s[0], t), reflect(s[1], t
));}
// 交差判定
BOOL intersect(const S &s, const S &t){
const int p = ccw(t[0], t[1], s[0], 1) * ccw(t[0], t[1], s[1], 1);
const int q = ccw(s[0], s[1], t[0], 1) * ccw(s[0], s[1], t[1], 1);
return (p>0||q>0) ? FALSE : (!p||!q) ? BORDER : TRUE;
}
BOOL intersect(const S &s, const L &l){
if(l.online(s[0]) || l.online(s[1])) return BORDER;
return (sig(outp(l.dir(), s[0]-l[0])) * sig(outp(l.dir(), s[1]-l[0])) <= 0);
}
// dist2: 距離の二乗, dist: 距離
R dist2(const L &l, const P &p){return norm(outp(l.dir(), p - l[0])) / norm(l.dir());}
R dist2(const S &s, const P &p){
if(inp(p-s[0], s.dir()) < EPS) return norm(p - s[0]);
if(inp(p-s[1], -s.dir()) < EPS) return norm(p - s[1]);
return dist2((const L &)s, p);
}
R dist2(const S &s, const L &l){
return intersect(s, l) ? .0 : min(dist2(l, s[0]), dist2(l, s[1]));
}
R dist2(const S &s, const S &t){
return intersect(s, t) ? .0 : min(min(dist2(s, t[0]), dist2(t, s[0])),
min(dist2(s, t[1]), dist2(t, s[1])));
}
template<class S, class T> R dist(const S& s, const T& t){return sqrtl(dist2(s, t));}
inline P crosspoint(const L &l, const L &m){
R A = outp(l.dir(), m.dir()), B = outp(l.dir(), l[1] - m[0]);
if(!sig(abs(A)) && !sig(abs(B))) return m[0]; // same line
if(abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
return m[0] + B / A * (m[1] - m[0]);
}



using pi = pair<int, R>;

int H[102];
vector<P> XY[102];
int beg[102];

vector<S> pt[102];
R D[128][128];


int main(){
    int n;
    while(cin >> n){
        if(n == 0)return 0;
        int su = 0;
        rep(i, n){
            int v;
            cin >> v >> H[i];
            XY[i].clear();
            rep(j, v){
                int x,y;
                cin >> x >> y;
                XY[i].push_back(P(x,y));
            }
            su += v*2;
        }
        rep(i,128)rep(j,128) D[i][j] = (i==j ? 0.0 : INF);


        int sita, phi;
        cin >> sita >> phi;
        R SITA = (R)sita*3.14159265358979323 /180;
        R PHI  =  (R)phi*3.14159265358979323 /180;
        P S, T;
        {
            int x,y;
            cin >> x >> y;
            S = P(x,y);
            cin >> x >> y;
            T = P(x,y);
        }
        rep(i, n){
            pt[i].clear();
            int v = XY[i].size();

            R r = H[i] / tan(PHI);
            //P d = -P(r*cos(SITA), r*sin(SITA));
            P d = -polar(r, SITA);
            rep(j, v){
                pt[i].emplace_back(XY[i][j], XY[i][(j+1)%v]);
            }
            rep(j, v){
                pt[i].emplace_back(XY[i][j] + d, XY[i][(j+1)%v] + d);
            }
            rep(j, v){
                pt[i].emplace_back(XY[i][j], XY[i][j] + d);
            }
            
            rep(a,v*2) reps(b,a+1, v*2) reps(c, b+1, v*2){
                int A = ccw(pt[i][a][0], pt[i][b][0], S);
                int B = ccw(pt[i][b][0], pt[i][c][0], S);
                int C = ccw(pt[i][c][0], pt[i][a][0], S);
                if(A != 0 && A == B && B == C) D[n][i] = D[i][n] = 0;
            }
            rep(a,v*2) reps(b,a+1, v*2) reps(c, b+1, v*2){
                int A = ccw(pt[i][a][0], pt[i][b][0], T);
                int B = ccw(pt[i][b][0], pt[i][c][0], T);
                int C = ccw(pt[i][c][0], pt[i][a][0], T);
                if(A != 0 && A == B && B == C) D[n+1][i] = D[i+1][n] = 0;
            }
            
            for(auto&S:pt[i]){
                //cout << "line(" << S[0].X<<", "<< S[0].Y<<", "<< S[1].X<<", "<< S[1].Y<<")"<<endl;
            }
        }
        //cout << "circle(" << S.X << ", " << S.Y << ", 1)" << endl;
        //cout << "circle(" << T.X << ", " << T.Y << ", 1)" << endl;



        rep(i, n)reps(j, i+1, n){
            R d = INF;
            for(auto&A : pt[i]) for(auto&B : pt[j]) {
                d = min(d, dist2(A,B));
            }
            D[i][j] = D[j][i] = sqrt(d);
        }
        rep(i, n){
            R d = D[n][i];
            for(auto&A : pt[i]){
                d = min(d, dist2(A, S));
            }
            D[i][n] = D[n][i] = sqrt(d);
        }
        rep(i, n){
            R d = D[n+1][i];
            for(auto&A : pt[i]){
                d = min(d, dist2(A, T));
            }
            D[i][n+1] = D[n+1][i] = sqrt(d);
        }
        D[n][n+1] = D[n+1][n] = abs(S-T);
        /*
        rep(i, n+2){
            rep(j, n+2){
                printf("%9.5lf", (double)D[i][j]);
            }
            puts("");
        }
        */
        rep(k, n+2)rep(i, n+2) rep(j, n+2){
            D[i][j] = D[j][i] = min(D[i][j] , D[i][k] + D[k][j]);
        }
        printf("%.9lf", (double)D[n][n+1]);
        puts("");

    }
}
/*
 */