#include <bits/stdc++.h>
const int maxn = 200010, maxm = 200010, maxq = 200010;
int n, p[maxn], go[maxn][19], m, a[maxm], b[maxm];
struct edge {
  int to;
  edge* next;
} E[maxn], *fir[maxn];
int fa[maxn], dep[maxn], siz[maxn], son[maxn], top[maxn];
void init(int i) {
  siz[i] = 1;
  for (edge* e = fir[i]; e; e = e->next) {
    fa[e->to] = i;
    dep[e->to] = dep[i] + 1;
    init(e->to);
    if (siz[e->to] > siz[son[i]]) son[i] = e->to;
    siz[i] += siz[e->to];
  }
}
void hld(int i) {
  for (edge* e = fir[i]; e; e = e->next) {
    top[e->to] = e->to == son[i] ? top[i] : e->to;
    hld(e->to);
  }
}
int lca(int i, int j) {
  while (top[i] != top[j])
    dep[top[i]] > dep[top[j]] ? i = fa[top[i]] : j = fa[top[j]];
  return dep[i] < dep[j] ? i : j;
}
int q, qu[maxq], qans[maxq], qtmp[maxq];
std::vector<int> pst[maxn], qst[maxn];
int pre[maxn], pos[maxn], now, B[maxn];
void add(int i) {
  for (; i <= n; i += i & -i) B[i]++;
}
int qry(int i) {
  int s = 0;
  for (; i; i -= i & -i) s += B[i];
  return s;
}
void dfs(int i) {
  pre[i] = ++now;
  for (int j = qst[i].size(); j--;) {
    int id = qst[i][j], u = qu[id];
    if (!pre[u]) {
      qst[u].push_back(id);
      qu[id] = i;
      qst[i][j] = -1;
    } else
      qtmp[id] = qry(pos[u]) - qry(pre[u] - 1);
  }
  for (int j = pst[i].size(); j--;)
    if (pre[pst[i][j]]) add(pre[pst[i][j]]);
  for (edge* e = fir[i]; e; e = e->next) {
    dfs(e->to);
  }
  for (int j = qst[i].size(); j--;) {
    int id = qst[i][j];
    if (id > -1) {
      int u = qu[id], s = qry(pos[u]) - qry(pre[u] - 1) - qtmp[id];
      if (s) qans[id]--;
    }
  }
  pos[i] = now;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", p + i);
    E[i] = (edge){i, fir[p[i]]};
    fir[p[i]] = E + i;
  }
  init(top[1] = 1);
  hld(1);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) *go[i] = i;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", a + i, b + i);
    int c = lca(a[i], b[i]);
    if (dep[c] < dep[*go[a[i]]]) *go[a[i]] = c;
    if (dep[c] < dep[*go[b[i]]]) *go[b[i]] = c;
    pst[a[i]].push_back(b[i]);
    if (a[i] != b[i]) pst[b[i]].push_back(a[i]);
  }
  for (int i = n; i > 1; i--)
    if (dep[*go[i]] < dep[*go[p[i]]]) *go[p[i]] = *go[i];
  for (int i = 1; i < 19; i++)
    for (int j = 1; j <= n; j++) go[j][i] = go[go[j][i - 1]][i - 1];
  int q;
  scanf("%d", &q);
  for (int id = 0; id < q; id++) {
    int u, v, s = 0;
    scanf("%d%d", &u, &v);
    int c = lca(u, v);
    for (int i = 19; i--;) {
      if (dep[go[u][i]] > dep[c]) s += 1 << i, u = go[u][i];
      if (dep[go[v][i]] > dep[c]) s += 1 << i, v = go[v][i];
    }
    if (dep[*go[u]] > dep[c] || dep[*go[v]] > dep[c])
      s = -1;
    else if (u == c) {
      if (v != c) s++;
    } else if (v == c)
      s++;
    else {
      s += 2;
      qu[id] = u;
      qst[v].push_back(id);
    }
    qans[id] = s;
  }
  dfs(1);
  for (int i = 0; i < q; i++) printf("%d\n", qans[i]);
}
