#include <bits/stdc++.h>
using namespace std;
int tot, n, t, m, fa[200020][19], f[200020][19], la[200020], id[200020],
    pre[200020], ne[200020], deep[200020], tmp[200020], clk, rt[200020], cnt;
vector<int> v[200020];
struct tree {
  int l, r, s;
} tr[200020 * 19];
inline void get(int &x) {
  char c = getchar();
  bool p = 0;
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') p = 1, c = getchar();
  x = c - '0', c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  if (p) x = -x;
}
struct edge {
  int v, ne;
} e[200020 << 1];
inline void addedge(int u, int v) {
  e[tot].v = v, e[tot].ne = la[u], la[u] = tot++;
}
inline void dfs(int u) {
  id[pre[u] = ++clk] = u;
  for (int i = 1; i < 19; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = la[u]; ~i; i = e[i].ne) {
    int v = e[i].v;
    if (v == fa[u][0]) continue;
    fa[v][0] = u, deep[v] = deep[u] + 1, dfs(v);
  }
  ne[u] = clk;
}
inline int lca(int u, int v) {
  if (deep[u] < deep[v]) swap(u, v);
  for (int i = 19 - 1; ~i; --i)
    if (deep[fa[u][i]] >= deep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = 19 - 1; ~i; --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
inline bool cmp(int a, int b) { return ne[a] < ne[b]; }
inline void pushup(int o) { tr[o].s = tr[tr[o].l].s + tr[tr[o].r].s; }
inline int update(int o, int l, int r, int x, int v) {
  int no = ++cnt;
  tr[no] = tr[o];
  if (l == r) {
    tr[no].s += v;
    return no;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    tr[no].l = update(tr[no].l, l, mid, x, v);
  else
    tr[no].r = update(tr[no].r, mid + 1, r, x, v);
  pushup(no);
  return no;
}
inline int query(int ro, int lo, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return tr[ro].s - tr[lo].s;
  int mid = (l + r) >> 1;
  if (qr <= mid)
    return query(tr[ro].l, tr[lo].l, l, mid, ql, qr);
  else if (ql > mid)
    return query(tr[ro].r, tr[lo].r, mid + 1, r, ql, qr);
  else
    return query(tr[ro].l, tr[lo].l, l, mid, ql, qr) +
           query(tr[ro].r, tr[lo].r, mid + 1, r, ql, qr);
}
void init() {
  cnt = rt[0] = fa[1][0] = clk = tot = 0;
  get(n);
  memset(la, -1, sizeof(la));
  memset(tr, 0, sizeof(tr));
  for (int u = 2; u <= n; ++u) {
    int v;
    get(v);
    addedge(u, v), addedge(v, u);
  }
  deep[1] = 1, dfs(1);
  for (int i = 1; i <= n; ++i) f[i][0] = i, tmp[i] = i;
  get(t);
  for (int i = 1; i <= t; ++i) {
    int x, y;
    get(x), get(y);
    if (pre[x] > pre[y]) swap(x, y);
    int z = lca(x, y);
    if (deep[z] < deep[f[x][0]]) f[x][0] = z;
    if (deep[z] < deep[f[y][0]]) f[y][0] = z;
    v[x].push_back(y);
  }
  std::sort(tmp + 1, tmp + n + 1, cmp);
  for (int i = n; i > 1; --i)
    if (deep[f[fa[i][0]][0]] > deep[f[i][0]]) f[fa[i][0]][0] = f[i][0];
  for (int i = 1; i < 19; ++i)
    for (int u = 1; u <= n; ++u) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int i = 1; i <= n; ++i) {
    rt[i] = rt[i - 1];
    for (int j = 0; j < v[id[i]].size(); ++j)
      rt[i] = update(rt[i], 1, n, pre[v[id[i]][j]], 1);
  }
}
void solve() {
  get(m);
  while (m--) {
    int a, b, ans = 0;
    get(a), get(b);
    if (pre[a] > pre[b]) swap(a, b);
    int c = lca(a, b);
    for (int i = 19 - 1; ~i; --i) {
      if (deep[f[a][i]] > deep[c]) a = f[a][i], ans += (1 << i);
      if (deep[f[b][i]] > deep[c]) b = f[b][i], ans += (1 << i);
    }
    if (ans > n) {
      printf("-1\n");
      continue;
    }
    if (a == c || b == c) {
      printf("%d\n", ans + 1);
      continue;
    }
    printf("%d\n",
           ans + 2 -
               ((bool)(query(rt[ne[a]], rt[pre[a] - 1], 1, n, pre[b], ne[b]))));
  }
}
int main() {
  init();
  solve();
  return 0;
}
