#include <bits/stdc++.h>
using namespace std;
const int N = 500505;
const int mod = 1e9 + 7;
int n, x;
vector<int> g[N];
int jump[N][21];
int up[N][21];
int tin[N], tout[N], timer;
vector<int> a[N];
vector<int> t[4 * N];
inline void dfs(int v, int p = 0) {
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i <= 20; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
  }
  tout[v] = timer;
}
inline int upper(int a, int b) {
  return tin[a] <= tin[b] && tout[b] <= tout[a];
}
inline int get_lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 20; i >= 0; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
inline void calc_jump(int v, int p = 0) {
  for (int to : g[v]) {
    if (to == p) continue;
    calc_jump(to, v);
    if (upper(jump[to][0], v)) {
      if (upper(jump[to][0], jump[v][0])) jump[v][0] = jump[to][0];
    }
  }
}
inline void merge(int v, int a, int b) {
  t[v].resize(t[a].size() + t[b].size());
  int i = 0;
  int j = 0;
  while (i < t[a].size() || j < t[b].size()) {
    if (i == t[a].size()) {
      t[v][i + j] = t[b][j++];
    } else if (j == t[b].size()) {
      t[v][i + j] = t[a][i++];
    } else if (t[a][i] < t[b][j]) {
      t[v][i + j] = t[a][i++];
    } else
      t[v][i + j] = t[b][j++];
  }
}
inline void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v].resize(a[tl].size());
    for (int i = 0; i < a[tl].size(); ++i) t[v][i] = a[tl][i];
    return;
  }
  int tm = (tl + tr) >> 1;
  build(v + v, tl, tm);
  build(v + v + 1, tm + 1, tr);
  merge(v, v + v, v + v + 1);
}
inline int get_cnt(int v, int tl, int tr, int l, int r, int x, int y) {
  if (l > r) return 0;
  if (tl == l && tr == r) {
    return upper_bound(t[v].begin(), t[v].end(), y) -
           lower_bound(t[v].begin(), t[v].end(), x);
  }
  int tm = (tl + tr) >> 1;
  return get_cnt(v + v, tl, tm, l, min(r, tm), x, y) +
         get_cnt(v + v + 1, tm + 1, tr, max(tm + 1, l), r, x, y);
}
inline int get_jump(int a, int b) {
  if (a == b) return 0;
  int ret = 0;
  int ans = 1e9;
  int done = 0;
  for (int j = 20; j >= 0; --j) {
    if (upper(jump[a][j], b))
      ans = min(ans, ret + (1 << j)), done = 1;
    else {
      ret += (1 << j);
      a = jump[a][j];
    }
  }
  if (upper(jump[a][0], b)) ans = min(ans, ret + 1), done = 1;
  if (!done) return 1e9;
  return ans;
}
inline bool can_one(int u, int v) {
  int k1 = get_cnt(1, 1, timer, tin[u], tout[u], tin[v], tout[v]);
  int k2 = get_cnt(1, 1, timer, tin[v], tout[v], tin[u], tout[u]);
  if (!upper(u, v) && !upper(v, u) && (k1 && k2) ||
      upper(u, v) && upper(jump[v][0], u) ||
      upper(v, u) && upper(jump[u][0], v)) {
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  tout[0] = 1e9;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    cin >> x;
    g[x].push_back(i);
  }
  dfs(1);
  int m;
  cin >> m;
  for (int i = 1; i <= n; ++i) jump[i][0] = i;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    int lca = get_lca(u, v);
    if (upper(lca, jump[u][0])) jump[u][0] = lca;
    if (upper(lca, jump[v][0])) jump[v][0] = lca;
    a[tin[v]].push_back(tin[u]);
    a[tin[u]].push_back(tin[v]);
  }
  calc_jump(1);
  for (int i = 1; i <= timer; ++i) sort(a[i].begin(), a[i].end());
  build(1, 1, timer);
  for (int j = 1; j <= 20; ++j) {
    for (int i = 1; i <= n; ++i) jump[i][j] = jump[jump[i][j - 1]][j - 1];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int u, v;
    cin >> u >> v;
    if (can_one(u, v)) {
      cout << 1 << '\n';
    } else {
      int lca = get_lca(u, v);
      if (!upper(jump[u][20], lca) || !upper(jump[v][20], lca)) {
        cout << -1 << '\n';
        continue;
      }
      int res = 0;
      for (int i = 20; i >= 0; --i) {
        int x = jump[u][i];
        if (!upper(x, v)) res = res + (1 << i), u = x;
      }
      for (int i = 20; i >= 0; --i) {
        int x = jump[v][i];
        if (!upper(x, u)) res = res + (1 << i), v = x;
      }
      res += 1 + !can_one(u, v);
      cout << res << '\n';
    }
  }
  return 0;
}
