#include <bits/stdc++.h>
using namespace std;
const int L = 1000000;
char LZH[L];
char *SSS, *TTT;
inline char gc() {
  if (SSS == TTT) {
    TTT = (SSS = LZH) + fread(LZH, 1, L, stdin);
    if (SSS == TTT) return -1;
  }
  return *SSS++;
}
inline int read() {
  int x = 0, f = 1;
  char c = gc();
  for (; c < '0' || c > '9'; c = gc())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = gc()) x = (x << 1) + (x << 3) + c - 48;
  return x * f;
}
const int maxn = 200002;
struct fotiletree {
  struct node {
    int ls, rs, sum;
  } t[maxn * 20];
  int cur;
  int p;
  void update(int &o, int l, int r) {
    t[++cur] = t[o];
    o = cur;
    t[o].sum++;
    if (l == r) return;
    int mid = (l + r) / 2;
    if (p <= mid)
      update(t[o].ls, l, mid);
    else
      update(t[o].rs, mid + 1, r);
  }
  int ql, qr;
  bool count(int lo, int ro, int l, int r) {
    if (ql <= l && qr >= r) return t[ro].sum > t[lo].sum;
    int mid = (l + r) / 2;
    if (ql <= mid && count(t[lo].ls, t[ro].ls, l, mid)) return 1;
    return qr > mid && count(t[lo].rs, t[ro].rs, mid + 1, r);
  }
} t;
struct graph {
  int n, m;
  struct edge {
    int to, next;
  } e[maxn * 2];
  int first[maxn];
  void init(int n) { this->n = n; }
  void addedge(int from, int to) {
    e[++m] = (edge){to, first[from]};
    first[from] = m;
  }
  int dep[maxn], fa[maxn], st[maxn], en[maxn], cl;
  int par[maxn][22];
  void dfs(int u) {
    st[u] = ++cl;
    par[u][0] = fa[u];
    for (int i = 1; i <= 20; i++) par[u][i] = par[par[u][i - 1]][i - 1];
    for (int i = first[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (fa[u] == v) continue;
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs(v);
    }
    en[u] = cl;
  }
  int lca(int u, int v) {
    if (dep[u] > dep[v]) swap(u, v);
    int t = dep[v] - dep[u];
    for (int i = 0; i <= 20; i++)
      if (t >> i & 1) v = par[v][i];
    if (u == v) return u;
    for (int i = 20; i >= 0; i--)
      if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
    return par[u][0];
  }
  inline int gt(int x, int y) { return dep[x] < dep[y] ? x : y; }
  int nxt[maxn], f[maxn][22];
  void dfs2(int u) {
    for (int i = first[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (v == fa[u]) continue;
      dfs2(v);
      nxt[u] = gt(nxt[u], nxt[v]);
    }
    f[u][0] = nxt[u];
  }
  vector<int> a[maxn];
  int rt[maxn];
  void add(int u, int v) {
    if (st[u] > st[v]) swap(u, v);
    int lc = lca(u, v);
    nxt[u] = gt(nxt[u], lc);
    nxt[v] = gt(nxt[v], lc);
    a[st[u]].push_back(st[v]);
  }
  void pre() {
    dfs2(1);
    for (int i = 1; i <= 20; i++)
      for (int j = 1; j <= n; j++) f[j][i] = f[f[j][i - 1]][i - 1];
    for (int i = 1; i <= n; i++) {
      rt[i] = rt[i - 1];
      for (int j = 0; j < a[i].size(); j++)
        t.p = a[i][j], t.update(rt[i], 1, n);
    }
  }
  pair<int, int> jump(int u, int to) {
    int ans = 0;
    for (int i = 20; i >= 0; i--)
      if (dep[f[u][i]] > dep[to]) u = f[u][i], ans += 1 << i;
    if (f[u][0] == u) return make_pair(-1, u);
    return make_pair(ans, u);
  }
  int query(int u, int v) {
    if (dep[u] < dep[v]) swap(u, v);
    if (u == v) return 0;
    int lc = lca(u, v);
    pair<int, int> x = jump(u, lc), y = jump(v, lc);
    if (lc == v) return x.first == -1 ? -1 : x.first + 1;
    if (x.first == -1 || y.first == -1) return -1;
    int ans = x.first + y.first + 1;
    int w = x.second, o = y.second;
    if (st[w] > st[o]) swap(w, o);
    t.ql = st[o], t.qr = en[o];
    if (!t.count(rt[st[w] - 1], rt[en[w]], 1, n)) ans++;
    return ans;
  }
} g;
int p[200002];
int main() {
  int n = read();
  g.init(n);
  for (int i = 2; i <= n; i++) {
    p[i] = read();
    g.addedge(i, p[i]);
    g.addedge(p[i], i);
  }
  g.dfs(1);
  for (int i = 1; i <= n; i++) g.nxt[i] = i;
  int m = read();
  while (m--) {
    int u = read(), v = read();
    g.add(u, v);
  }
  g.pre();
  int q = read();
  while (q--) {
    int u = read(), v = read();
    printf("%d\n", g.query(u, v));
  }
}
