#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;
}

Measured memory_bytes: 3612