#include <bits/stdc++.h>
using namespace std;
int n, m, lev[200010], paa[200010][20], mina[200010], ti, lf[200010],
    rg[200010], dfa[200010];
vector<int> mat[200010], co[200010], pos[200010], route[200010];
void dfs(int p, int pa) {
  if (p == pa) ti = 0;
  lf[p] = ++ti;
  dfa[ti] = p;
  for (auto x : mat[p]) {
    if (x == pa) continue;
    paa[x][0] = p;
    lev[x] = lev[p] + 1;
    dfs(x, p);
    if (lev[mina[p]] > lev[mina[x]]) mina[p] = mina[x];
  }
  rg[p] = ti;
}
void sparceTable() {
  for (int i = 1; i <= 19; i++)
    for (int p = 1; p <= n; p++) {
      int go = paa[p][i - 1];
      if (go != -1) paa[p][i] = paa[go][i - 1];
    }
}
int levPa(int p, int l, int bs) {
  if (lev[p] == l || bs == -1) return p;
  int go = paa[p][bs];
  if (go != -1 && lev[go] >= l)
    return levPa(go, l, bs);
  else
    return levPa(p, l, bs - 1);
}
int lca(int f, int s, int bs) {
  if (bs == -1) return paa[f][0];
  int go = paa[f][bs], so = paa[s][bs];
  if (go != so)
    return lca(go, so, bs);
  else
    return lca(f, s, bs - 1);
}
int finLca(int f, int s) {
  if (lev[f] < lev[s]) swap(f, s);
  f = levPa(f, lev[s], 19);
  if (f == s)
    return f;
  else
    return lca(f, s, 19);
}
int can(int p, int tar) {
  if (lev[p] <= lev[tar]) return 0;
  if (mina[p] == p) return -200010;
  return 1 + can(mina[p], tar);
}
int jump(int p, int j) {
  if (j <= 0) return p;
  return jump(mina[p], j - 1);
}
int prin[200010], value[200010];
pair<int, int> poo[200010];
int tree[4 * 200010];
void update(int idx, int b, int e, int p, int val) {
  if (b > p || e < p) return;
  if (b == e) {
    tree[idx] = val;
    return;
  }
  int mid = (b + e) >> 1;
  update((idx << 1), b, mid, p, val);
  update((idx << 1) + 1, mid + 1, e, p, val);
  tree[idx] = tree[(idx << 1)] + tree[(idx << 1) + 1];
  return;
}
int query(int idx, int b, int e, int st, int en) {
  if (b > en || e < st) return 0;
  if (st <= b && e <= en) return tree[idx];
  int mid = (b + e) >> 1;
  return query((idx << 1), b, mid, st, en) +
         query((idx << 1) + 1, mid + 1, e, st, en);
}
int sz[200010], bigChild[200010], nex[200010], dhur[200010];
void dsudfs(int p, int pa) {
  sz[p] = route[p].size();
  int mx = -1;
  bigChild[p] = -1;
  for (auto x : mat[p]) {
    if (x != pa) {
      dsudfs(x, p);
      sz[p] += sz[x];
      if (sz[x] > mx) mx = sz[x], bigChild[p] = x;
    }
  }
}
int finNex(int p) {
  if (p == nex[p])
    return p;
  else
    return nex[p] = finNex(nex[p]);
}
void up(int p, int v) {
  int l = lf[p];
  while (l <= rg[p]) {
    int x = dfa[l];
    for (auto y : route[x]) {
      update(1, 1, 200010, lf[y], v);
    }
    if (route[x].size() == 0) nex[l - 1] = l;
    l = nex[l] + 1;
  }
}
void dsu(int p, int pa, int keep) {
  for (auto x : mat[p])
    if (x != pa && x != bigChild[p]) dsu(x, p, 0);
  if (bigChild[p] != -1) dsu(bigChild[p], p, 1);
  for (auto x : route[p]) update(1, 1, 200010, lf[x], 1);
  for (auto x : mat[p]) {
    if (x == pa || x == bigChild[p]) continue;
    up(x, 1);
  }
  int lol = 0, y;
  for (auto x : co[p]) {
    y = pos[p][lol];
    lol++;
    if (query(1, 1, 200010, lf[x], rg[x])) prin[y]--;
  }
  if (!keep) up(p, 0);
}
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    mat[x].push_back(i);
    mat[i].push_back(x);
  }
  memset(paa, -1, sizeof(paa));
  dfs(1, 1);
  sparceTable();
  int q, lc, a, b;
  scanf("%d", &q);
  for (int i = 1; i <= n; i++) mina[i] = i;
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    lc = finLca(x, y);
    if (lev[mina[x]] > lev[lc]) mina[x] = lc;
    if (lev[mina[y]] > lev[lc]) mina[y] = lc;
    route[x].push_back(y);
    route[y].push_back(x);
  }
  dfs(1, 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    lc = finLca(x, y);
    a = can(x, lc);
    b = can(y, lc);
    if (a < 0 || b < 0) {
      prin[i] = -1;
    } else {
      prin[i] = a + b;
      a = jump(x, a - 1);
      b = jump(y, b - 1);
      if (lc != x && lc != y) {
        co[a].push_back(b);
        pos[a].push_back(i);
      }
    }
  }
  dsudfs(1, 1);
  for (int i = lf[1]; i <= rg[1]; i++) nex[i] = i;
  dsu(1, 1, 0);
  for (int i = 1; i <= q; i++) {
    printf("%d\n", prin[i]);
  }
  return 0;
}
