#include <bits/stdc++.h>
using namespace std;
int n;
struct Edge {
  int u, v, Next;
} G[200010];
int head[200010], tot;
int in[200010], out[200010], dfs_clock;
int lowest[200010];
int h[200010];
int ft[200010][20];
int low[200010][20];
inline void add(int u, int v) {
  G[++tot] = (Edge){u, v, head[u]};
  head[u] = tot;
}
inline void dfs(int x, int fa) {
  h[x] = h[fa] + 1;
  ft[x][0] = fa;
  in[x] = ++dfs_clock;
  for (int i = 1; i <= 19; ++i) {
    ft[x][i] = ft[ft[x][i - 1]][i - 1];
  }
  for (int i = head[x]; i != -1; i = G[i].Next) {
    dfs(G[i].v, x);
  }
  out[x] = dfs_clock;
}
inline int lca(int x, int y) {
  if (h[x] < h[y]) swap(x, y);
  int t = h[x] - h[y];
  for (int i = 0; i <= 19; ++i) {
    if ((1 << i) & t) {
      x = ft[x][i];
    }
  }
  if (x == y) return x;
  for (int i = 19; i >= 0; --i) {
    if (ft[x][i] != ft[y][i]) {
      x = ft[x][i];
      y = ft[y][i];
    }
  }
  return ft[x][0];
}
inline void dfs_low(int x, int fa) {
  for (int i = head[x]; i != -1; i = G[i].Next) {
    dfs_low(G[i].v, x);
    if (h[lowest[G[i].v]] < h[lowest[x]]) {
      lowest[x] = lowest[G[i].v];
    }
  }
}
bool ban[200010];
inline bool is_(int x, int y) { return (in[x] <= in[y] && out[y] <= out[x]); }
inline bool reachable(int x, int LCA) {
  x = low[x][19];
  return is_(x, LCA);
}
int ans[200010], cnt[200010];
vector<pair<int, int> > que[200010];
vector<int> bus[200010];
int C[200010];
inline void add(int x) {
  for (int i = x; i <= n; i += (i & -i)) {
    C[i]++;
  }
}
inline int query(int l, int r) {
  int ret = 0;
  for (; r; r -= (r & -r)) {
    ret += C[r];
  }
  --l;
  for (; l; l -= (l & -l)) {
    ret -= C[l];
  }
  return ret;
}
inline void Do(int x) {
  for (int i = 0; i < que[x].size(); ++i) {
    int X = que[x][i].first, y = que[x][i].second;
    cnt[y] -= query(in[X], out[X]);
  }
  for (int i = 0; i < bus[x].size(); ++i) {
    add(in[bus[x][i]]);
  }
  for (int i = head[x]; i != -1; i = G[i].Next) {
    Do(G[i].v);
  }
  for (int i = 0; i < que[x].size(); ++i) {
    int X = que[x][i].first, y = que[x][i].second;
    cnt[y] += query(in[X], out[X]);
    if (cnt[y] > 0) {
      ans[y]--;
    }
  }
}
int main() {
  scanf("%d", &n);
  memset(head, -1, sizeof(head));
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    add(p, i);
  }
  dfs(1, 0);
  for (int i = 1; i <= n; ++i) {
    lowest[i] = i;
  }
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    bus[u].push_back(v);
    bus[v].push_back(u);
    int LCA = lca(u, v);
    lowest[u] = (h[lowest[u]] < h[LCA] ? lowest[u] : LCA);
    lowest[v] = (h[lowest[v]] < h[LCA] ? lowest[v] : LCA);
  }
  dfs_low(1, 0);
  for (int i = 1; i <= n; ++i) {
    low[i][0] = lowest[i];
  }
  for (int i = 1; i <= 19; ++i) {
    for (int j = 1; j <= n; ++j) {
      low[j][i] = low[low[j][i - 1]][i - 1];
    }
  }
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    int LCA = lca(u, v);
    if (!reachable(u, LCA) || !reachable(v, LCA)) {
      ban[i] = true;
    }
    for (int j = 19; j >= 0; --j) {
      if (!is_(low[u][j], v)) {
        u = low[u][j];
        ans[i] += (1 << j);
      }
    }
    for (int j = 19; j >= 0; --j) {
      if (!is_(low[v][j], u)) {
        v = low[v][j];
        ans[i] += (1 << j);
      }
    }
    if (u != LCA && v != LCA) {
      que[u].push_back(make_pair(v, i));
    }
    ans[i] += (v != LCA);
    ans[i] += (u != LCA);
  }
  Do(1);
  for (int i = 1; i <= q; ++i) {
    if (ban[i])
      puts("-1");
    else
      printf("%d\n", ans[i]);
  }
}
