#include <bits/stdc++.h>
using namespace std;
const int maxn = 100;
int dist[maxn][maxn];
int d[maxn][maxn];
int used[maxn][maxn];
vector<vector<int> > es;
int bus[maxn][maxn];
int cnt[maxn];
int main() {
  int n, m, a, b;
  while (scanf("%d%d%d%d", &n, &m, &a, &b) >= 1) {
    --a, --b;
    es = vector<vector<int> >(n);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) dist[i][j] = (i == j) ? 0 : ((int)1E9);
    for (int i = 0; i < m; i++) {
      int s, t;
      scanf("%d%d", &s, &t);
      --s, --t;
      dist[s][t] = 1;
    }
    for (int k = 0; k < n; k++)
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) bus[i][j] = (i == j);
    int k;
    scanf("%d", &k);
    for (int iter = 0; iter < k; iter++) {
      int S, T;
      scanf("%d%d", &S, &T);
      S--, T--;
      if (dist[S][T] == ((int)1E9)) continue;
      for (int i = 0; i < n; i++) cnt[i] = 0;
      for (int i = 0; i < n; i++) {
        if (dist[S][T] == dist[S][i] + dist[i][T]) {
          cnt[dist[S][i]]++;
        }
      }
      for (int i = 0; i < n; i++) {
        if (dist[S][T] == dist[S][i] + dist[i][T] && cnt[dist[S][i]] == 1)
          bus[i][T] = 1;
      }
    }
    for (int i = 0; i < n; i++)
      for (int j = 0; j < n; j++) d[i][j] = ((int)1E9), used[i][j] = 0;
    for (int j = 0; j < n; j++)
      if (bus[b][j]) d[b][j] = 0;
    for (int iter = 0; iter < n * n; iter++) {
      int v = -1, tr = -1;
      for (int i = 0; i < n; i++)
        for (int j = 0; j < n; j++)
          if (!used[i][j] && (v == -1 || d[v][tr] > d[i][j])) v = i, tr = j;
      if (v == -1) break;
      used[v][tr] = 1;
      for (int i = 0; i < n; i++) {
        if (bus[v][tr]) d[v][i] = min(d[v][i], d[v][tr] + 1);
        if (dist[i][tr] != dist[i][v] + dist[v][tr]) continue;
        if (dist[i][v] != 1) continue;
        int cur = 0;
        for (int y = 0; y < n; y++)
          if (dist[i][y] == 1 && dist[i][y] + dist[y][tr] == dist[i][tr])
            cur = max(cur, d[y][tr]);
        d[i][tr] = min(d[i][tr], cur);
      }
    }
    printf("%d\n", d[a][a] == ((int)1E9) ? -1 : d[a][a]);
  }
  return 0;
}
