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>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

namespace geo{
    using real_num = double;
    constexpr real_num eps = 1e-9;
    constexpr real_num PI = 3.14159265358979323846264338327950;
    
    inline int sgn(real_num x){
        if(x < -eps) return -1;
        if(x > eps) return 1;
        return 0;
    }

    inline bool eq(real_num x, real_num y){
        return sgn(x - y) == 0;
    }

    inline bool ge(real_num x, real_num y){
        return sgn(x - y) == 1;
    }

    inline bool le(real_num x, real_num y){
        return sgn(x - y) == -1;
    }

    inline bool geq(real_num x, real_num y){
        return sgn(x - y) >= 0;
    }

    inline bool leq(real_num x, real_num y){
        return sgn(x - y) <= 0;
    }

    struct Point{
        real_num x, y;
        Point(real_num x = 0, real_num y = 0): x(x), y(y){}

        Point operator+(const Point &p){
            return {x + p.x, y + p.y};
        }

        Point operator-(const Point &p){
            return {x - p.x, y - p.y};
        }

        Point operator*(const real_num k){
            return {x * k, y * k};
        }

        Point operator/(const real_num k){
            return {x / k, y / k};
        }

        real_num operator*(const Point &p){
            return x * p.x + y * p.y;
        }

        real_num operator^(const Point &p){
            return x * p.y - y * p.x;
        }

        bool operator==(const Point &p){
            return eq(x, p.x) && eq(y, p.y);
        }

        bool operator<(const Point &p) const{
            if(eq(x, p.x)) return le(y, p.y);
            return le(x, p.x);
        }
    };

    using Vec = Point;
    using Points = vector<Point>;
    using Polygon = vector<Point>;

    real_num norm(Point p){
        return p.x * p.x + p.y * p.y;
    }

    real_num abs(Point p){
        return sqrt(norm(p));
    }

    Point rot(Point p, real_num t){
        return {p.x * cos(t) - p.y * sin(t), p.x * sin(t) + p.y * cos(t)};
    }

    constexpr int CCW_COUNTER_CLOCKWISE = 1;
    constexpr int CCW_CLOCKWISE = -1;
    constexpr int CCW_ONLINE_BACK = -2;
    constexpr int CCW_ONLINE_FRONT = 2;
    constexpr int CCW_ON_SEGMENT = 0;

    inline int ccw(Point a, Point b, Point c){
        Vec v = b - a, w = c - a;
        if(ge(v ^ w, 0)) return CCW_COUNTER_CLOCKWISE;
        if(le(v ^ w, 0)) return CCW_CLOCKWISE;
        if(le(v * w, 0)) return CCW_ONLINE_BACK;
        if(le((a - b) * (c - b), 0)) return CCW_ONLINE_FRONT;
        return CCW_ON_SEGMENT;
    }

    bool has_intersection_ss(Point a, Point b, Point c, Point d){
        return ccw(a, b, c) * ccw(a, b, d) <= 0 && ccw(c, d, a) * ccw(c, d, b) <= 0;
    }

    real_num distance_lp(Point a, Vec v, Point p){
        return abs(v ^ (p-a) / abs(v));
    }

    real_num distance_sp(Point a, Point b, Point p){
        if(le((b - a) * (p - a), 0)) return abs(p - a);
        if(le((a - b) * (p - b), 0)) return abs(p - b);
        return distance_lp(a, b - a, p);
    }

    real_num distance_ss(Point a, Point b, Point c, Point d){
        if(has_intersection_ss(a, b, c, d)) return 0;
        return min({distance_sp(a, b, c), distance_sp(a, b, d), distance_sp(c, d, a), distance_sp(c, d, b)});
    }

    int point_in_polygon(Point a, Polygon &p){
        int n = p.size(), wn = 0;
        rep(i, n){
            int j = (i + 1) % n;
            if(eq(distance_sp(p[i], p[j], a), 0)) return 1;
            else if(leq(p[i].y, a.y) && le(a.y, p[j].y)){
                wn += (ccw(a, p[i], p[j]) == CCW_COUNTER_CLOCKWISE);
            }
            else if(leq(p[j].y, a.y) && le(a.y, p[i].y)){
                wn -= (ccw(a, p[i], p[j]) == CCW_CLOCKWISE);
            }
        }
        return wn == 0 ? 0 : 2;
    }

    Polygon convex_hull(Points p){
        int n = p.size();
        sort(p.begin(), p.end());
        Polygon ch(2 * n);
        int k = 0;
        rep(i, n){
            while(k > 1 && le((ch[k - 1] - ch[k - 2]) ^ (p[i] - ch[k - 1]), 0)) --k;
            ch[k++] = p[i];
        }
        for(int i = n - 2, t = k; i >= 0; --i){
            while(k > t && le((ch[k - 1] - ch[k - 2]) ^ (p[i] - ch[k - 1]), 0)) --k;
            ch[k++] = p[i];
        }
        ch.resize(k - 1);
        return ch;
    }
}

using namespace geo;
int n;

void solve(){
    real_num h[n];
    Points p[n];
    rep(i, n){
        int K;
        scanf("%d%lf", &K, &h[i]);
        p[i].resize(K * 2);
        rep(j, K) scanf("%lf%lf", &p[i][j].x, &p[i][j].y);
    }
    real_num theta, phi;
    scanf("%lf%lf", &theta, &phi);
    rep(i, n){
        rep(j, p[i].size() / 2){
            Point q = p[i][j] + rot({-h[i] / tan(phi * PI / 180), 0}, theta * PI / 180);
            p[i][j + p[i].size() / 2] = q;
        }
        p[i] = convex_hull(p[i]);
    }

    real_num dist[n + 2][n + 2];
    rep(i, n){
        dist[i][i] = 0;
        For(j, i + 1, n){
            real_num tmp = INF;
            rep(k, p[i].size())rep(l, p[j].size()){
                chmin(tmp, distance_ss(p[i][k], p[i][(k + 1) % p[i].size()], p[j][l], p[j][(l + 1) % p[j].size()]));
            }
            dist[i][j] = dist[j][i] = tmp;
        }
    }
    Point sp, tp;
    scanf("%lf%lf%lf%lf", &sp.x, &sp.y, &tp.x, &tp.y);
    dist[n][n] = dist[n + 1][n + 1] = 0;
    rep(i, n){
        if(point_in_polygon(sp, p[i]) >= 1){
            dist[i][n] = dist[n][i] = 0;
            continue;
        }
        real_num tmp = INF;
        rep(j, p[i].size()){
            chmin(tmp, distance_sp(p[i][j], p[i][(j + 1) % p[i].size()], sp));
        }
        dist[i][n] = dist[n][i] = tmp;
    }
    rep(i, n){
        if(point_in_polygon(tp, p[i]) >= 1){
            dist[i][n + 1] = dist[n + 1][i] = 0;
            continue;
        }
        real_num tmp = INF;
        rep(j, p[i].size()){
            chmin(tmp, distance_sp(p[i][j], p[i][(j + 1) % p[i].size()], tp));
        }
        dist[i][n + 1] = dist[n + 1][i] = tmp;
    }
    dist[n][n + 1] = dist[n + 1][n] = abs(sp - tp);

    rep(k, n + 2)rep(i, n + 2)rep(j, n + 2){
        chmin(dist[i][j], dist[i][k] + dist[k][j]);
    }
    printf("%.10lf\n", dist[n][n + 1]);
}

int main(){
    while(scanf("%d", &n) && n){
        solve();
    }
}