#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int x = 0, f = 1;
  char ch;
  do {
    ch = getchar();
    if (ch == '-') f = -1;
  } while (ch < '0' || ch > '9');
  do {
    x = x * 10 + ch - '0';
    ch = getchar();
  } while (ch >= '0' && ch <= '9');
  return x * f;
}
const int N = 200010, LOG = 19;
struct node {
  int u, v, next;
} edge[N << 1];
int last[N], le;
void add(int u, int v) {
  edge[++le].u = u, edge[le].v = v, edge[le].next = last[u], last[u] = le;
  edge[++le].u = v, edge[le].v = u, edge[le].next = last[v], last[v] = le;
}
int dp[LOG][N], deep[N], pre[N], nxt[N], tp[LOG][N], lt, n, m, tans[N];
vector<int> G1[N], G2[N], Gnum[N], lans[N];
void dfs1(int u, int fa) {
  pre[u] = ++lt, deep[u] = deep[fa] + 1;
  for (int i = last[u]; i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs1(v, u);
  }
  nxt[u] = lt;
}
void getdp() {
  for (int i = 1; i < LOG; ++i) {
    for (int j = 1; j <= n; ++j) dp[i][j] = dp[i - 1][dp[i - 1][j]];
  }
}
void gettp() {
  for (int i = 1; i < LOG; ++i) {
    for (int j = 1; j <= n; ++j) tp[i][j] = tp[i - 1][tp[i - 1][j]];
  }
}
int getlca(int u, int v) {
  if (deep[u] < deep[v]) swap(u, v);
  for (int i = LOG - 1; ~i; --i)
    if (deep[dp[i][u]] >= deep[v]) u = dp[i][u];
  if (u == v) return u;
  for (int i = LOG - 1; ~i; --i)
    if (dp[i][u] != dp[i][v]) u = dp[i][u], v = dp[i][v];
  return dp[0][u];
}
int sumv[N << 2];
inline void pushup(int o) { sumv[o] = sumv[o << 1] + sumv[o << 1 | 1]; }
void qadd(int o, int l, int r, int x, int v) {
  if (l == r) {
    sumv[o] += v;
    return;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    qadd(o << 1, l, mid, x, v);
  else
    qadd(o << 1 | 1, mid + 1, r, x, v);
  pushup(o);
}
int qsum(int o, int l, int r, int x, int y) {
  if (x <= l && r <= y) return sumv[o];
  int mid = (l + r) >> 1;
  if (y <= mid)
    return qsum(o << 1, l, mid, x, y);
  else if (x > mid)
    return qsum(o << 1 | 1, mid + 1, r, x, y);
  else
    return qsum(o << 1, l, mid, x, mid) +
           qsum(o << 1 | 1, mid + 1, r, mid + 1, y);
}
void dfs2(int u, int fa) {
  lans[u].resize(G2[u].size());
  for (int i = G2[u].size() - 1; ~i; --i) {
    int v = G2[u][i];
    lans[u][i] = qsum(1, 1, lt, pre[v], nxt[v]);
  }
  for (int i = G1[u].size() - 1; ~i; --i) {
    int v = G1[u][i];
    qadd(1, 1, lt, pre[v], 1);
  }
  for (int i = last[u]; i; i = edge[i].next) {
    int v = edge[i].v;
    if (v == fa) continue;
    dfs2(v, u);
  }
  for (int i = G2[u].size() - 1; ~i; --i) {
    int v = G2[u][i];
    if (qsum(1, 1, lt, pre[v], nxt[v]) == lans[u][i]) ++tans[Gnum[u][i]];
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) tp[0][i] = i;
  for (int i = 2; i <= n; ++i) {
    dp[0][i] = read();
    add(dp[0][i], i);
  }
  dfs1(1, 0);
  getdp();
  m = read();
  while (m--) {
    int u = read(), v = read(), lca = getlca(u, v);
    tp[0][u] = min(tp[0][u], lca);
    tp[0][v] = min(tp[0][v], lca);
    if (pre[u] > pre[v]) swap(u, v);
    G1[u].push_back(v);
  }
  for (int i = n; i; --i) tp[0][dp[0][i]] = min(tp[0][dp[0][i]], tp[0][i]);
  gettp();
  int q = read();
  for (int i = 1; i <= q; ++i) {
    int u = read(), v = read(), lca = getlca(u, v);
    tans[i] = 1;
    for (int j = LOG - 1; ~j; --j)
      if (deep[tp[j][u]] > deep[lca]) tans[i] += (1 << j), u = tp[j][u];
    for (int j = LOG - 1; ~j; --j)
      if (deep[tp[j][v]] > deep[lca]) tans[i] += (1 << j), v = tp[j][v];
    if (deep[tp[0][u]] > deep[lca] || deep[tp[0][v]] > deep[lca])
      tans[i] = -1;
    else if (u != lca && v != lca) {
      if (pre[u] > pre[v]) swap(u, v);
      G2[u].push_back(v);
      Gnum[u].push_back(i);
    }
  }
  dfs2(1, 0);
  for (int i = 1; i <= q; ++i) printf("%d\n", tans[i]);
  return 0;
}
