Problem: John is playing a famous console game named 'Tales of Algorithmers.' Now he is facing the last dungeon called 'Blue Forest.' To find out the fastest path to run through the very complicated dungeon, he tried to draw up the dungeon map.

The dungeon consists of several floors. Each floor can be described as a connected simple plane graph. Vertices of the graph are identified by X-Y coordinate, and the length of an edge is calculated by Euclidean distance. A vertex may be equipped with a one-way warp gate. If John chooses to use the gate, it brings John to another vertex in a possibly different floor. The distance between a warp gate and its destination is considered as 0.

One vertex has at most one warp gate, though some vertices might be the destination of multiple warp gates.

He believed he made one map for each floor, however after drawing maps of all the floors, he noticed that he might have made a few mistakes. He might have drawn the same floor several times, and might have forgotten to mark some warp gates in the maps. However, he was sure he marked all warp gates at least once. So if the maps of same floor are unified to one map, all the warp gates must be described there. Luckily there are no floors which have the same shape as the other floors, so if two (or more) maps can be unified, they must be the maps of the same floor. Also, there is no floor which is circular symmetric (e.g. a regular triangle and a square).

Map A and map B can be unified if map B can be transformed to map A using only rotation and parallel translation. Since some of the warp gates on maps might be missing, you should not consider the existence of warp gates when checking unification. If it is possible to unify map A and map B, a vertex on map A and the corresponding vertex on map B are considered as 'identical' vertices. In other words, you should treat warp gates on map B as those on map A where the warp gates are located on the corresponding vertices on map A. Destinations of warp gates should be treated similarly. After that you can forget map B. It is guaranteed that if both map A and map B have warp gates which are on the identical vertices, the destinations of them are also identical.

Remember, your task is to find the shortest path from the entrance to the exit of the dungeon, using the unified maps.



Input

The input consists of multiple datasets. Each dataset is in the following format.

n
component1 component2 ...
componentn sl sn
dl dn


n is a positive integer indicating the number of maps. componenti describes the i-th map in the following format.

A
x1 y1
x2 y2
...
xA yA
B
s1 d1
s2 d2
...
sB dB
C sn1 dl1 dn1
sn2 dl2 dn2
...
snC dlC dnC


A denotes the number of vertices in the map. Each of the following A lines contains two integers xi and yi representing the coordinates of the i-th vertex in the 2-dimensional plane. B denotes the number of the edges connecting the vertices in the map. Each of the following B lines contains two integers representing the start and the end vertex of each edge. Vertices on the same map are numbered from 1.

C denotes the number of warp gates. Each of the following C lines has three integers describing a warp gate. The first integer is the vertex where the warp gate is located. The second and the third integer are the indices of the map and the vertex representing the destination of the warp gate, respectively. Similarly to vertices, maps are also numbered from 1.

After the description of all maps, two lines follow. The rst line contains two integers sl and dl , meaning that the entrance of the dungeon is located in the sl-th map, at the vertex dl. The last line has two integers sn and dn, similarly describing the location of the exit.

The values in each dataset satisfy the following conditions:

* 1 ≤ n ≤ 50,
* 3 ≤ A ≤ 20,
* A - 1 ≤ B ≤ A(A - 1)/2,
* 0 ≤ C ≤ A, and
* -10,000 ≤ xi, yi ≤ 10,000.

Output

For each dataset, print the distance of the shortest path from the entrance to the exit. The output should not contain an absolute error greater than 10-1. If there is no route, print -1.

Example

Input

2
5
0 0
10 0
20 0
30 0
30 10
4
1 2
2 3
3 4
4 5
2
1 2 4
3 2 2
5
-10 0
0 0
0 -10
0 -20
0 -30
4
1 2
2 3
3 4
4 5
1
4 1 3
1 1
2 1
4
3
4 3
0 0
5 0
2
1 2
2 3
0
3
0 0
3 4
0 5
2
1 2
1 3
1
2 3 4
4
0 13
0 0
13 0
13 13
4
1 2
1 4
2 3
2 4
0
4
5 12
0 0
-7 17
-12 5
4
1 2
2 3
2 4
4 3
0
1 1
4 1
4
3
0 0
2 0
0 4
2
1 2
1 3
0
3
0 0
-2 0
0 4
2
1 2
1 3
1
1 4 1
3
0 0
1 0
0 2
2
1 2
1 3
1
1 4 1
3
0 0
2 0
0 4
2
1 2
2 3
0
1 1
4 1
0


Output

10.0000000000
41.3847763109
-1.000000000

Solution (in CPP):

Solution:
#include<bits/stdc++.h>
#define f first
#define s second
#define ff f,f
#define fs f.s
#define sf s.f
#define ss s.s
#define mp make_pair
#define MAX 51
#define inf 1e10
#define eps (1e-11)
#define pi M_PI
#define equals(a,b) (fabs((a)-(b))<eps)
using namespace std;

typedef pair<double,double> Pd;
typedef pair<int,int> P;
typedef pair<Pd,Pd> PP;

class Point{
public:
  double x,y;
  Point(double x=0,double y=0):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);}
  Point operator/(double k){ return Point(x/k,y/k);}
  bool operator<(Point p)const{ return (x!=p.x ? x<p.x : y<p.y);}
  bool operator==(Point p)const{ return fabs(x-p.x)<eps && fabs(y-p.y)<eps;}

  double abs(){ return sqrt(norm());}
  double norm(){ return (x*x+y*y);}
};
typedef Point Vector;

double norm(Vector a){ return (a.x*a.x+a.y*a.y);}
double abs(Vector a){ return sqrt(norm(a));}
double dot(Vector a,Vector b){ return (a.x*b.x+a.y*b.y);}
double cross(Vector a,Vector b){ return (a.x*b.y-a.y*b.x);}

class edge{
  public:
    int l,n;
    double cost;
    edge(int l,int n,double cost):l(l),n(n),cost(cost){}
};

class State{
  public:
    int l,n;
    double cost;
    State(int l,int n,double cost):l(l),n(n),cost(cost){}
    bool operator<(State s)const{ return s.cost<cost; }
};

int n,sl,sn,dl,dn;
vector<Point> vp[MAX];
vector<P> vs[MAX];
vector<edge> e[MAX][MAX];

void init(){
  for(int i=0;i<MAX;i++){
    vp[i].clear();
    vs[i].clear();
    for(int j=0;j<MAX;j++)e[i][j].clear();
  }
}

double getAngle(Vector a,Vector b){
  double r=acos(dot(a,b)/(abs(a)*abs(b)))*180/pi;
  if(cross(a,b)<-eps)r=360-r;
  return r;
}

double dijkstra(){
  double d[MAX][MAX];
  for(int i=0;i<MAX;i++)for(int j=0;j<MAX;j++)d[i][j]=inf;
  priority_queue<State> pq;
  pq.push(State(sl,sn,0));
  d[sl][sn]=0;

  while(pq.size()){
    State u=pq.top();
    pq.pop();
    if(d[u.l][u.n]-u.cost<-eps)continue;

    for(int i=0;i<e[u.l][u.n].size();i++){
      edge E=e[u.l][u.n][i];
      if(u.cost+E.cost-d[E.l][E.n]<-eps){
        d[E.l][E.n]=u.cost+E.cost;
        pq.push(State(E.l,E.n,d[E.l][E.n]));
      }
    }
  }
  if(d[dl][dn]==inf)return -1;
  return d[dl][dn];
}

void check(int a,int b){
  if(vs[a].size()!=vs[b].size())return;
  if(vp[a].size()!=vp[b].size())return;
  P v=vs[a][0];
  map<int,int> ver;
  Point A=vp[a][v.f],B=vp[a][v.s];
  for(int i=0;i<vs[b].size();i++){
    P u=vs[b][i];
    Point C=vp[b][u.f],D=vp[b][u.s];
    if(!equals(abs(B-A),abs(D-C)))continue;
    map<PP,P> mp;
    for(int j=0;j<vs[b].size();j++){
      P w=vs[b][j];
      Point E=vp[b][w.f];
      Point F=vp[b][w.s];
      PP tmp=PP(Pd(abs(E-C),getAngle(D-C,E-C)),
                Pd(abs(F-C),getAngle(D-C,F-C)));
      mp[tmp]=w;
    }
    bool flag=true;
    for(int j=0;j<vs[a].size();j++){
      P w=vs[a][j];
      Point E=vp[a][w.f];
      Point F=vp[a][w.s];
      PP tmp=PP(Pd(abs(E-A),getAngle(B-A,E-A)),
                Pd(abs(F-A),getAngle(B-A,F-A)));
      if(mp.find(tmp)==mp.end()){
        flag=false;
        break;
      }
      ver[mp[tmp].f]=w.f;
      ver[mp[tmp].s]=w.s;
    }
    if(flag){
      for(int j=0;j<vp[b].size();j++){
        int k=ver[j];
        e[b][j].push_back(edge(a,k,0));
        e[a][k].push_back(edge(b,j,0));
      }
      return;
    }
  }
  return;
}

int main()
{
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      int a,b,c,x,y,z,s,d;
      cin>>a;
      for(int j=0;j<a;j++){
        cin>>x>>y;
        vp[i].push_back(Point(x,y));
      }
      cin>>b;
      for(int j=0;j<b;j++){
        cin>>s>>d;
        s--;d--;
        vs[i].push_back(mp(s,d));
        vs[i].push_back(mp(d,s));
        e[i][s].push_back(edge(i,d,abs(vp[i][s]-vp[i][d])));
        e[i][d].push_back(edge(i,s,abs(vp[i][s]-vp[i][d])));
      }
      cin>>c;
      for(int j=0;j<c;j++){
        cin>>x>>y>>z;
        x--;y--;z--;
        e[i][x].push_back(edge(y,z,0));
      }
    }
    cin>>sl>>sn>>dl>>dn;
    sl--;sn--;dl--;dn--;
    
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++)check(i,j);
    }
    printf("%.10f\n",dijkstra());
  }
  return 0;
}