#include <bits/stdc++.h>
using namespace std;
int pre[400005], to[400005], las[400005], inc;
int fa[400005][21], jmp[400005][21], dep[400005], dfn[400005], out[400005], dft;
int n, m, q, ans[400005];
void ins(int a, int b) {
  pre[++inc] = las[a];
  las[a] = inc, to[inc] = b;
}
void dfs(int x, int par) {
  fa[x][0] = par, dfn[x] = ++dft, dep[x] = dep[par] + 1;
  for (int i = 1; i <= 20; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = las[x]; i; i = pre[i])
    if (to[i] != par) dfs(to[i], x);
  out[x] = dft;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20, delta = dep[x] - dep[y]; i >= 0; i--)
    if (delta >> i & 1) x = fa[x][i];
  if (x == y) return x;
  for (int i = 20; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void GetJmp1(int x) {
  for (int i = las[x]; i; i = pre[i]) {
    int y = to[i];
    GetJmp1(y);
    if (!jmp[x][0] || (dep[jmp[x][0]] > dep[jmp[y][0]] && jmp[y][0]))
      jmp[x][0] = jmp[y][0];
  }
}
void GetJmp2(int x) {
  for (int i = 1; i <= 20; i++) jmp[x][i] = jmp[jmp[x][i - 1]][i - 1];
  for (int i = las[x]; i; i = pre[i]) GetJmp2(to[i]);
}
int C[400005];
void Add(int x, int v) {
  for (int i = x; i < 400005; i += (i & -i)) C[i] += v;
}
int Query(int x) {
  int ret = 0;
  for (int i = x; i; i ^= (i & -i)) ret += C[i];
  return ret;
}
struct node {
  int x, l, r, ty, id;
} op[400005 * 4];
int tot, sm[400005 * 4];
int cmp(node a, node b) { return a.x == b.x ? a.ty < b.ty : a.x < b.x; }
int main() {
  scanf("%d", &n);
  for (int i = 2, x; i <= n; i++) scanf("%d", &x), ins(x, i);
  dfs(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y, anc;
    scanf("%d%d", &x, &y), anc = LCA(x, y);
    if (!jmp[x][0] || dep[jmp[x][0]] > dep[anc]) jmp[x][0] = anc;
    if (!jmp[y][0] || dep[jmp[y][0]] > dep[anc]) jmp[y][0] = anc;
    op[++tot] = (node){dfn[x], dfn[y], 0, 0, 0};
    op[++tot] = (node){dfn[y], dfn[x], 0, 0, 0};
  }
  GetJmp1(1), GetJmp2(1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y, anc;
    scanf("%d%d", &x, &y), anc = LCA(x, y);
    if (anc == x || anc == y) {
      int p = (anc == x ? y : x);
      for (int j = 20; j >= 0; j--)
        if (jmp[p][j] && dep[jmp[p][j]] > dep[anc])
          p = jmp[p][j], ans[i] += (1 << j);
      if (!jmp[p][0] || dep[jmp[p][0]] > dep[anc]) ans[i] = -1;
    } else {
      for (int j = 20; j >= 0; j--)
        if (jmp[x][j] && dep[jmp[x][j]] > dep[anc])
          x = jmp[x][j], ans[i] += (1 << j);
      for (int j = 20; j >= 0; j--)
        if (jmp[y][j] && dep[jmp[y][j]] > dep[anc])
          y = jmp[y][j], ans[i] += (1 << j);
      ans[i]++;
      if (!jmp[x][0] || !jmp[y][0] || dep[jmp[x][0]] > dep[anc] ||
          dep[jmp[y][0]] > dep[anc])
        ans[i] = -1;
      op[++tot] = (node){dfn[x], dfn[y], out[y], -1, i},
      op[++tot] = (node){out[x], dfn[y], out[y], 1, i};
    }
  }
  sort(op + 1, op + tot + 1, cmp);
  for (int i = 1; i <= tot; i++) {
    if (op[i].ty == -1) sm[op[i].id] = Query(op[i].r) - Query(op[i].l - 1);
    if (op[i].ty == 0) Add(op[i].l, 1);
    if (op[i].ty == 1)
      sm[op[i].id] = Query(op[i].r) - Query(op[i].l - 1) - sm[op[i].id];
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i] == -1)
      printf("-1\n");
    else
      printf("%d\n", ans[i] - (sm[i] > 0) + 1);
  }
  return 0;
}
