#include <bits/stdc++.h>
using namespace std;
inline int read() {
  int s = 0, w = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') w = -1;
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9')
    s = (s << 1) + (s << 3) + (ch ^ 48), ch = getchar();
  return s * w;
}
struct edge {
  int v, nxt;
} e[200010 << 1];
int n, m, q, cnt, tot;
int head[200010], fa[200010], size[200010], son[200010], top[200010],
    dfn[200010], dep[200010], out[200010];
int f[200010][21], up[200010], p[21], ans[200010], c[200010];
vector<int> E[200010];
vector<pair<int, int> > Q[200010];
int lowbit(int x) { return x & -x; }
void Add(int x, int val) {
  for (int i = x; i <= n; i += lowbit(i)) c[i] += val;
}
int query(int x) {
  int res = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) res += c[i];
  return res;
}
void add(int u, int v) { e[++cnt].v = v, e[cnt].nxt = head[u], head[u] = cnt; }
void dfs1(int u, int ff) {
  out[u] = dfn[u] = ++tot, size[u] = 1, fa[u] = ff, dep[u] = dep[ff] + 1;
  for (int i = head[u]; i != 0; i = e[i].nxt)
    if (e[i].v != ff) {
      dfs1(e[i].v, u);
      size[u] += size[e[i].v], out[u] = max(out[u], out[e[i].v]);
      if (size[e[i].v] > size[son[u]]) son[u] = e[i].v;
    }
}
void dfs2(int u, int topf) {
  top[u] = topf;
  if (son[u]) dfs2(son[u], topf);
  for (int i = head[u]; i != 0; i = e[i].nxt)
    if (!top[e[i].v]) dfs2(e[i].v, e[i].v);
}
int LCA(int x, int y) {
  while (top[x] != top[y]) {
    if (dep[top[x]] < dep[top[y]]) swap(x, y);
    x = fa[top[x]];
  }
  return dep[x] < dep[y] ? x : y;
}
void dfs3(int u, int ff) {
  for (int i = head[u]; i != 0; i = e[i].nxt)
    if (e[i].v != ff) {
      dfs3(e[i].v, u);
      if (f[e[i].v][1] != 0 &&
          (dep[f[e[i].v][1]] < dep[f[u][1]] || f[u][1] == 0))
        f[u][1] = f[e[i].v][1];
    }
}
void dfs4(int u, int ff) {
  for (int i = 2; i <= 20; i++) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int i = head[u]; i != 0; i = e[i].nxt)
    if (e[i].v != ff) dfs4(e[i].v, u);
}
bool check(int u, int pos) {
  for (int i = 20; i >= 0; i--)
    if (dep[f[u][i]] <= dep[pos] && f[u][i] != 0) return 1;
  return 0;
}
pair<int, int> get(int u, int pos) {
  int dis = 0;
  if (!check(u, pos)) return make_pair(0, -0x3f3f3f3f);
  for (int i = 20; i >= 1; i--)
    if (dep[f[u][i]] > dep[pos] && f[u][i] != 0) u = f[u][i], dis += p[i - 1];
  return make_pair(u, dis);
}
void dfs(int u, int ff) {
  vector<int> Num;
  for (pair<int, int> x : Q[u])
    Num.push_back(query(out[x.first]) - query(dfn[x.first] - 1));
  for (int x : E[u]) Add(dfn[x], 1);
  for (int i = head[u]; i != 0; i = e[i].nxt)
    if (e[i].v != ff) dfs(e[i].v, u);
  for (int i = 0; i < Q[u].size(); i++) {
    pair<int, int> x = Q[u][i];
    if (query(out[x.first]) - query(dfn[x.first] - 1) != Num[i])
      ans[x.second]--;
  }
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) {
    int p = read();
    add(p, i), add(i, p);
  }
  dfs1(1, 0), dfs2(1, 1);
  for (int i = 1; i <= n; i++) f[i][0] = i;
  p[0] = 1;
  for (int i = 1; i <= 20; i++) p[i] = p[i - 1] << 1;
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    if (dfn[x] > dfn[y]) swap(x, y);
    E[x].push_back(y);
    int lca = LCA(x, y);
    if (dep[lca] < dep[f[x][1]] || !f[x][1]) f[x][1] = lca;
    if (dep[lca] < dep[f[y][1]] || !f[y][1]) f[y][1] = lca;
  }
  dfs3(1, 0), dfs4(1, 0);
  q = read();
  for (int i = 1; i <= q; i++) {
    int x = read(), y = read(), lca = LCA(x, y);
    if (lca == x || lca == y) {
      if (x == lca) swap(x, y);
      pair<int, int> tmp = get(x, y);
      ans[i] = tmp.second + 1 - 2;
      continue;
    }
    pair<int, int> tmp = get(x, lca);
    ans[i] += tmp.second, x = tmp.first;
    tmp = get(y, lca);
    ans[i] += tmp.second, y = tmp.first;
    if (!x || !y) continue;
    if (dfn[x] > dfn[y]) swap(x, y);
    Q[x].push_back(make_pair(y, i));
  }
  for (int i = 1; i <= q; i++) ans[i] += 2;
  dfs(1, 0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i] < 0 ? -1 : ans[i]);
  return 0;
}
