#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e9 + 10, MAX = 2e5 + 10, MOD = 1e9 + 7, MAXL = 20;
void OUT(long double o, int x) {
  cout << fixed << setprecision(x) << o;
  return;
}
int dp[MAXL][MAX], h[MAX], st[MAX], en[MAX], now = 0, ans[MAX];
pair<int, int> go[MAXL][MAX];
vector<int> adj[MAX];
set<int> sack[MAX];
vector<pair<pair<int, int>, int> > qu[MAX];
void dfs(int v) {
  h[v] = h[dp[0][v]] + 1;
  go[0][v] = {h[v], v};
  st[v] = ++now;
  for (int i = 1; i <= 18; i++) dp[i][v] = dp[i - 1][dp[i - 1][v]];
  for (int u : adj[v]) dfs(u);
  en[v] = now;
}
void dfs1(int v) {
  for (int u : adj[v]) {
    dfs1(u);
    go[0][v] = min(go[0][v], go[0][u]);
  }
}
void dfs2(int v) {
  for (int i = 1; i <= 18; i++) go[i][v] = go[i - 1][go[i - 1][v].second];
  for (int u : adj[v]) dfs2(u);
}
void dfs3(int v) {
  pair<int, int> x = {1, v};
  for (int u : adj[v]) {
    dfs3(u);
    x = max({sack[u].size(), u}, x);
  }
  sack[v].swap(sack[x.second]);
  for (int u : adj[v]) {
    for (int k : sack[u]) sack[v].insert(k);
  }
  for (pair<pair<int, int>, int> u : qu[v]) {
    int y = *sack[v].lower_bound(u.first.first);
    if (y <= u.first.second) ans[u.second]--;
  }
}
int gp(int v, int x) {
  for (int i = 0; i <= 18; i++)
    if (x & (1 << i)) v = dp[i][v];
  return v;
}
int lca(int v, int u) {
  if (h[v] > h[u]) swap(v, u);
  u = gp(u, h[u] - h[v]);
  if (v == u) return v;
  for (int i = 18; i >= 0; i--)
    if (dp[i][v] != dp[i][u]) v = dp[i][v], u = dp[i][u];
  return dp[0][v];
}
pair<int, int> dis(int v, int p) {
  int x = 0;
  for (int i = 18; i >= 0; i--) {
    if (go[i][v].first > h[p]) {
      x += (1 << i);
      v = go[i][v].second;
    }
  }
  return {x + 1, v};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, q;
  cin >> n;
  for (int i = 1; i <= n; i++) sack[i].insert(INF);
  dp[0][1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> dp[0][i];
    adj[dp[0][i]].push_back(i);
  }
  dfs(1);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int v, u;
    cin >> v >> u;
    if (h[v] > h[u]) swap(v, u);
    int z = lca(v, u);
    go[0][u] = min(go[0][u], {h[z], z});
    if (!(st[v] < st[u] && st[u] <= en[v])) {
      go[0][v] = min(go[0][v], {h[z], z});
      sack[v].insert(st[u]);
      sack[u].insert(st[v]);
    }
  }
  dfs1(1);
  dfs2(1);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int v, u;
    cin >> v >> u;
    if (h[v] > h[u]) swap(v, u);
    if (!(st[v] < st[u] && st[u] <= en[v])) {
      int z = lca(v, u);
      if (go[18][u].first > h[z] || go[18][v].first > h[z])
        ans[i] = -1;
      else {
        pair<int, int> x = dis(u, z), y = dis(v, z);
        ans[i] = x.first + y.first;
        qu[x.second].push_back({{st[y.second], en[y.second]}, i});
      }
    } else {
      if (go[18][u].first > h[v])
        ans[i] = -1;
      else
        ans[i] = dis(u, v).first;
    }
  }
  dfs3(1);
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}
