#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <map>
#include <queue>

using namespace std;

typedef pair<int,int> pii;

const int INF=1000000000;
int n,m;
map<string,int> indice;
vector<pii> points;
vector<int> G[1001];
// node,どちらから来たか
int d[1001][4];
int src,dst;

const int dy[]={-1,0,1,0};
const int dx[]={0,1,0,-1};

int dijkstra(int ang){
  for(int i=0;i<1001;i++)
    for(int j=0;j<4;j++)d[i][j]=INF;
  priority_queue<pair<int,pii> > pq;
  d[src][ang]=0;
  pq.push(make_pair(0,pii(src,ang)));
  while(pq.size()){
    pair<int,pii> p=pq.top();pq.pop();
    int cost=p.first;
    int node=p.second.first;
    int curAng=p.second.second;
    if(d[node][curAng]<cost)continue;
    // まっすぐ進む
    for(int i=0;i<G[node].size();i++){
      int to=G[node][i];
      int movey=points[to].first-points[node].first;
      int movex=points[to].second-points[node].second;
      if((movey>0&&dy[curAng]>0)
	 ||(movey<0&&dy[curAng]<0)
	 ||(movex<0&&dx[curAng]<0)
	 ||(movex>0&&dx[curAng]>0)){
	if(d[to][curAng]>cost+1){
	  d[to][curAng]=cost+1;
	  pq.push(make_pair(d[to][curAng],pii(to,curAng)));
	}
      }
    }
    // 左に曲がる
    for(int i=0;i<G[node].size();i++){
      int to=G[node][i];
      int movey=points[to].first-points[node].first;
      int movex=points[to].second-points[node].second;
      int nxtAng=(curAng+1)%4;
      if((movey>0&&dy[nxtAng]>0)
	 ||(movey<0&&dy[nxtAng]<0)
	 ||(movex<0&&dx[nxtAng]<0)
	 ||(movex>0&&dx[nxtAng]>0)){
	if(d[to][nxtAng]>cost+1){
	  d[to][nxtAng]=cost+1;
	  pq.push(make_pair(d[to][nxtAng],pii(to,nxtAng)));
	}
      }
    }
  }
  int res=INF;
  for(int i=0;i<4;i++)res=min(res,d[dst][i]);
  return res;
}

int main(){

  while(cin>>n>>m&&(n|m)){
    indice.clear();points.clear();
    for(int i=0;i<1001;i++)G[i].clear();
    for(int i=0;i<n;i++){
      string name;
      int x,y;
      cin>>name>>x>>y;
      indice[name]=i;
      points.push_back(pii(y,x));
    }
    for(int i=0;i<m;i++){
      string p,q;
      cin>>p>>q;
      int a=indice[p];
      int b=indice[q];
      G[a].push_back(b);G[b].push_back(a);
    }
    string a,b;
    cin>>a>>b;
    src=indice[a];dst=indice[b];
    int res=INF;
    for(int i=0;i<4;i++)res=min(res,dijkstra(i));
    if(res==INF)cout<<"impossible"<<endl;
    else cout<<res+1<<endl;
  }
  
  return 0;
}