#include<bits/stdc++.h>
using namespace std;

int M,N;
typedef pair<int,int> P;
int X[1111],Y[1111];

const int INF = (1<<29);

//up,right,down,left;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
P G[1111][4];

void add_edge(int i,int j){
  if( X[i] != X[j] ) {
    if( X[i] > X[j] ) swap( i, j );
    G[i][1] = P(j, X[j]-X[i]);
    G[j][3] = P(i, X[j]-X[i]);
  } else {
    if( Y[i] > Y[j] ) swap( i, j );
    G[i][0] = P(j, Y[j]-Y[i]);
    G[j][2] = P(i, Y[j]-Y[i]);
  }
}

struct state{
  int id,d,ky,ps;
  state(){}
  state(int id,int d,int ky,int ps):id(id),d(d),ky(ky),ps(ps){}
  bool operator<(const state& st) const{
    if( ky == st.ky ) return ps > st.ps;
    return ky > st.ky;
  }
};

P H[1111][4];

bool isright(int d,int nd){
  if( (d+1)%4 == nd ) return true;
  return false;
}

void solve(int s,int t){
  for(int i=0;i<=M;i++)
    for(int j=0;j<4;j++)
      H[i][j] = P(INF,INF);
  priority_queue<state> q;  
  q.emplace( s, 0, 0, 1 );
  q.emplace( s, 1, 0, 1 );
  q.emplace( s, 2, 0, 1 );
  q.emplace( s, 3, 0, 1 );
  H[s][0] = P(0,1);
  H[s][1] = P(0,1);
  H[s][2] = P(0,1);
  H[s][3] = P(0,1);

  while( !q.empty() ) {
    state st = q.top(); q.pop();    
    if( H[st.id][st.d] < P(st.ky,st.ps) ) continue;
    //cout << st.id << " "<< st.d << " "<< st.ky << " " << st.ps << endl;
    if(st.id==t){
      cout << st.ps << endl;
      return;                            
    }
    for(int i=0;i<4;i++){
      if( isright( st.d, i ) ) continue;
      if( (i+2)%4 == st.d ) continue;
      P to = G[st.id][i]; if( to.second == INF ) continue;
      P nc = P( st.ky + to.second, st.ps + 1 );
      if( H[to.first][i] > nc ){
        H[to.first][i] = nc;
        q.emplace( to.first, i, nc.first, nc.second);
      }      
    }
  }
  cout << "impossible" << endl;  
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  while( cin >> M >> N && (M|N) ){
    for(int i=0;i<M;i++)
      for(int j=0;j<4;j++)
        G[i][j] = P(INF,INF);
    unordered_map<string,int> mp;
    for(int i=0;i<M;i++){
      string s; cin >> s;
      cin >> X[i] >> Y[i];
      mp[s] = i;
    }
    for(int i=0;i<N;i++){
      string a,b; cin >> a >> b;
      add_edge( mp[a], mp[b] );
    }
    /*  for(int i=0;i<M;i++){
      for(int j=0;j<4;j++){
        cout << i << ": " << j << " -> " << G[i][j].first << " "<< G[i][j].second << endl;
      }
    }
    */
    string src,dst; cin >> src >> dst;
    solve(mp[src],mp[dst]);
  }
}