#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <cassert>
using namespace std;

const int MAXM = 1001;
const int INF = 1<<28;
int M, N;
map<string,int> id;
int px[MAXM], py[MAXM];
vector<int> G[MAXM];
pair<int,int> cost[4][MAXM];

struct State {
  int d, v;
  pair<int,int> cost;
  bool operator < (const State &s) const {
    return cost > s.cost;
  }
};

int getDir(int prev, int now) {
  int dx = px[now] - px[prev];
  int dy = py[now] - py[prev];
  assert(dx == 0 && dy != 0 || dx != 0 && dy == 0);
  if(dx >=  1) return 0;
  if(dy >=  1) return 1;
  if(dx <= -1) return 2;
  if(dy <= -1) return 3;
  assert(false);
  return -1;
}

int getDist(int prev, int now) {
  int dx = px[now] - px[prev];
  int dy = py[now] - py[prev];
  return abs(dx) + abs(dy);
}

int bfs(int src, int dst) {
  fill(cost[0], cost[4], make_pair(INF,INF));
  cost[0][src] = make_pair(0,0);
  cost[1][src] = make_pair(0,0);
  cost[2][src] = make_pair(0,0);

  cost[3][src] = make_pair(0,0);
  priority_queue<State> que;
  que.push((State){0,src,make_pair(0,0)});
  que.push((State){1,src,make_pair(0,0)});
  que.push((State){2,src,make_pair(0,0)});
  que.push((State){3,src,make_pair(0,0)});
  while(que.size()) {
    State s = que.top();
    que.pop();
    if(cost[s.d][s.v] != s.cost) continue;
    if(s.v == dst) return s.cost.second;
    for(int k = 0; k < G[s.v].size(); ++k) {
      int nv = G[s.v][k];
      int nd = getDir(s.v, nv);
      pair<int,int> ncost
        = make_pair(s.cost.first + getDist(s.v, nv), s.cost.second + 1);
      if((nd-s.d+4)%4 > 1) continue;
      if(cost[nd][nv] < ncost) continue;
      cost[nd][nv] = ncost;
      que.push((State){nd, nv, ncost});
    }
  }
  return INF;
}

int main() {
  while(cin >> M >> N && (M|N)) {
    fill(G, G+MAXM, vector<int>());
    id.clear();
    for(int i = 0; i < M; ++i) {
      string s;
      cin >> s >> px[i] >> py[i];
      id[s] = i;
    }
    for(int i = 0; i < N; ++i) {
      string s, t;
      cin >> s >> t;
      G[id[s]].push_back(id[t]);
      G[id[t]].push_back(id[s]);
    }
    string src, dst;
    cin >> src >> dst;
    int res = bfs(id[src], id[dst]);
    if(res == INF) cout << "impossible" << endl;
    else cout << res+1 << endl;
  }
  return 0;
}