#include <bits/stdc++.h>
using namespace std;
const int N = 2 * 1000 * 100 + 10, LG = 20;
int n, par[N][LG], nxt[N][LG], h[N], st[N], en[N], TM;
vector<int> adj[N], vec[N], seg[N << 2];
void dfs(int v) {
  st[v] = TM++;
  for (auto u : adj[v]) {
    h[u] = h[v] + 1;
    dfs(u);
  }
  en[v] = TM;
}
int lca(int v, int u) {
  bool d = false;
  if (v == 5 && u == 6) d = true;
  if (h[v] < h[u]) swap(v, u);
  for (int i = 0; i < LG; i++)
    if ((1 << i) & (h[v] - h[u])) v = par[v][i];
  if (v == u) return v;
  for (int i = LG - 1; i >= 0; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return par[v][0];
}
pair<int, int> ans(int v, int u) {
  int res = 0;
  for (int i = LG - 1; i >= 0; i--)
    if (h[u] < h[nxt[v][i]]) {
      v = nxt[v][i];
      res ^= 1 << i;
    }
  return {res, v};
}
void build(int l = 0, int r = n, int id = 1) {
  if (l + 1 == r) {
    seg[id] = vec[l];
    sort(seg[id].begin(), seg[id].end());
    return;
  }
  int mid = l + r >> 1;
  build(l, mid, id << 1), build(mid, r, id << 1 | 1);
  merge(seg[id << 1].begin(), seg[id << 1].end(), seg[id << 1 | 1].begin(),
        seg[id << 1 | 1].end(), back_inserter(seg[id]));
}
bool get(int s, int e, int x, int y, int l = 0, int r = n, int id = 1) {
  if (s <= l && e >= r)
    return (bool)(lower_bound(seg[id].begin(), seg[id].end(), y) -
                  lower_bound(seg[id].begin(), seg[id].end(), x));
  if (s >= r || e <= l) return false;
  int mid = l + r >> 1;
  return (get(s, e, x, y, l, mid, id << 1) |
          get(s, e, x, y, mid, r, id << 1 | 1));
}
int query(int v, int u) {
  int w = lca(v, u);
  if (h[nxt[v][LG - 1]] > h[w] || h[nxt[u][LG - 1]] > h[w]) return -1;
  pair<int, int> a = ans(v, w);
  pair<int, int> b = ans(u, w);
  if (w == v || w == u ||
      get(st[a.second], en[a.second], st[b.second], en[b.second]))
    return a.first + b.first + 1;
  return a.first + b.first + 2;
}
int main() {
  ios::sync_with_stdio(false), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 1; i < n; i++) {
    cin >> par[i][0];
    par[i][0]--;
    adj[par[i][0]].push_back(i);
    nxt[i][0] = i;
  }
  for (int i = 1; i < LG; i++)
    for (int v = 0; v < n; v++) par[v][i] = par[par[v][i - 1]][i - 1];
  dfs(0);
  int m;
  cin >> m;
  for (int i = 0, a, b; i < m; i++) {
    cin >> a >> b;
    a--, b--;
    int w = lca(a, b);
    for (auto v : {a, b})
      if (h[w] < h[nxt[v][0]]) nxt[v][0] = w;
    vec[st[a]].push_back(st[b]);
    vec[st[b]].push_back(st[a]);
  }
  build();
  for (int v = n - 1; v >= 0; v--)
    for (auto u : adj[v])
      if (h[nxt[v][0]] > h[nxt[u][0]]) nxt[v][0] = nxt[u][0];
  for (int i = 1; i < LG; i++)
    for (int v = 0; v < n; v++) nxt[v][i] = nxt[nxt[v][i - 1]][i - 1];
  int Q;
  cin >> Q;
  while (Q--) {
    int v, u;
    cin >> v >> u;
    --v, --u;
    cout << query(v, u) << '\n';
  }
  return 0;
}
