#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9 + 7;
const int maxn = 2e5 + 5;
vector<int> g[maxn];
int depth = 0, bn = 0, b[maxn << 1];
int f[maxn << 1], dfn[maxn], dr[maxn], ft[maxn];
int fp[maxn][20], ans[maxn], cnt[maxn];
vector<int> fq[maxn];
vector<pair<int, int> > sq[maxn];
void dfs(int u, int fa) {
  int tmp = ++depth;
  b[++bn] = tmp;
  f[tmp] = u;
  dfn[u] = bn;
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs(v, u);
    b[++bn] = tmp;
  }
  dr[u] = depth;
}
int st[maxn << 1][20];
int lg[maxn << 1];
void st_init() {
  for (int i = 2; i < maxn * 2; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = bn; i >= 1; --i) {
    st[i][0] = b[i];
    for (int j = 1; i + (1 << j) - 1 <= bn; ++j)
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
  }
}
int rmq(int l, int r) {
  int k = lg[r - l + 1];
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}
int lca(int a, int b) {
  if (a == b) return a;
  if (dfn[a] > dfn[b]) swap(a, b);
  int k = rmq(dfn[a], dfn[b]);
  return f[k];
}
void update(int &x, int y) {
  if (y && (!x || dfn[x] > dfn[y])) x = y;
}
void dfs2(int u, int fa) {
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs2(v, u);
    if (fp[v][0] != u) update(fp[u][0], fp[v][0]);
  }
}
void dfs3(int u, int fa) {
  for (int i = 1; i < 20; i++) fp[u][i] = fp[fp[u][i - 1]][i - 1];
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs3(v, u);
  }
}
void add(int x) {
  while (x < maxn) {
    ft[x]++;
    x += x & (-x);
  }
}
int query(int x) {
  int res = 0;
  while (x > 0) {
    res += ft[x];
    x -= x & (-x);
  }
  return res;
}
int main() {
  int n, m, u, v, i, j, k;
  scanf("%d", &n);
  for (i = 2; i <= n; i++) {
    scanf("%d", &u);
    g[u].push_back(i);
  }
  dfs(1, 0);
  st_init();
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    k = lca(u, v);
    if (k != u) update(fp[u][0], k);
    if (k != v) update(fp[v][0], k);
    if (dfn[u] > dfn[v]) swap(u, v);
    fq[b[dfn[v]]].push_back(b[dfn[u]]);
  }
  dfs2(1, 0);
  dfs3(1, 0);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    k = lca(u, v);
    if (dfn[u] > dfn[v]) swap(u, v);
    for (j = 19; j >= 0; j--) {
      if (dfn[fp[u][j]] > dfn[k]) {
        ans[i] += 1 << j;
        u = fp[u][j];
      }
      if (dfn[fp[v][j]] > dfn[k]) {
        ans[i] += 1 << j;
        v = fp[v][j];
      }
    }
    if (u == k) {
      if (!fp[v][0])
        ans[i] = -1;
      else
        ans[i]++;
    } else {
      if (!fp[u][0] || !fp[v][0])
        ans[i] = -1;
      else {
        ans[i] += 2;
        sq[b[dfn[v]] - 1].push_back(pair<int, int>(u, -i));
        sq[dr[v]].push_back(pair<int, int>(u, i));
      }
    }
  }
  for (i = 0; i <= n; i++) {
    for (auto e : fq[i]) add(e);
    for (auto e : sq[i]) {
      k = query(dr[e.first]) - query(b[dfn[e.first]] - 1);
      if (e.second < 0)
        cnt[-e.second] -= k;
      else
        cnt[e.second] += k;
    }
  }
  for (i = 1; i <= m; i++) {
    if (cnt[i]) ans[i]--;
    printf("%d\n", ans[i]);
  }
  return 0;
}
