#include <bits/stdc++.h>
using namespace std;
const int maxn = 200005;
int n, m, q, ans[maxn], sum[maxn];
struct edge {
  int to, next;
} e[maxn * 2];
int h[maxn], tot;
int Time, fa[maxn], siz[maxn], dep[maxn], son[maxn], dfn[maxn], low[maxn],
    top[maxn];
int f[maxn][20], cnt;
vector<int> route[maxn];
int Sum[maxn];
struct node {
  int Id, x, y1, y2;
  bool operator<(const node &a) const { return x != a.x ? x < a.x : !Id; }
} s[maxn * 5];
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
inline void add(int u, int v) {
  e[++tot] = (edge){v, h[u]};
  h[u] = tot;
  e[++tot] = (edge){u, h[v]};
  h[v] = tot;
}
void dfs1(int u) {
  siz[u] = 1;
  dfn[u] = ++Time;
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa[u]) {
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs1(v);
      siz[u] += siz[v];
      if (siz[v] > siz[son[u]]) son[u] = v;
    }
  low[u] = Time;
}
void dfs2(int u) {
  if (son[u]) top[son[u]] = top[u], dfs2(son[u]);
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa[u] && v != son[u]) top[v] = v, dfs2(v);
}
inline int get_lca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] > dep[top[v]])
      u = fa[top[u]];
    else
      v = fa[top[v]];
  }
  return dep[u] < dep[v] ? u : v;
}
void dfs3(int u) {
  f[u][0] = u;
  for (int v : route[u]) f[u][0] = dep[v] < dep[f[u][0]] ? v : f[u][0];
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa[u]) {
      dfs3(v);
      f[u][0] = dep[f[v][0]] < dep[f[u][0]] ? f[v][0] : f[u][0];
    }
  if (f[u][0] == u) f[u][0] = 0;
}
void insert(int x, int a) {
  while (x <= n) {
    Sum[x] += a;
    x += x & (-x);
  }
}
int query(int x) {
  int res = 0;
  while (x) {
    res += Sum[x];
    x -= x & (-x);
  }
  return res;
}
int main() {
  n = gi();
  for (int i = 2; i <= n; ++i) add(i, gi());
  dfs1(1);
  top[1] = 1;
  dfs2(1);
  m = gi();
  for (int a, b, lca, i = 1; i <= m; ++i) {
    a = gi();
    b = gi();
    lca = get_lca(a, b);
    route[a].push_back(lca);
    route[b].push_back(lca);
    s[++cnt] = (node){0, dfn[a], 0, dfn[b]};
    s[++cnt] = (node){0, dfn[b], 0, dfn[a]};
  }
  dep[0] = n + 1;
  dfs3(1);
  for (int j = 0; j < 20; ++j)
    for (int i = 1; i <= n; ++i)
      if (f[i][j]) f[i][j + 1] = f[f[i][j]][j];
  q = gi();
  for (int u, v, lca, i = 1; i <= q; ++i) {
    u = gi();
    v = gi();
    lca = get_lca(u, v);
    for (int j = 19; j >= 0; --j)
      if (f[u][j] && dep[f[u][j]] > dep[lca]) u = f[u][j], ans[i] += (1 << j);
    for (int j = 19; j >= 0; --j)
      if (f[v][j] && dep[f[v][j]] > dep[lca]) v = f[v][j], ans[i] += (1 << j);
    if ((!f[u][0] && u != lca) || (!f[v][0] && v != lca)) {
      ans[i] = sum[i] = -1;
      continue;
    }
    if (u == lca || v == lca)
      ++ans[i], sum[i] = -1;
    else
      s[++cnt] = (node){-i, dfn[u] - 1, dfn[v], low[v]},
      s[++cnt] = (node){i, low[u], dfn[v], low[v]};
  }
  stable_sort(s + 1, s + cnt + 1);
  for (int i = 1; i <= cnt; ++i)
    if (!s[i].Id)
      insert(s[i].y2, 1);
    else {
      if (s[i].Id < 0)
        sum[-s[i].Id] -= query(s[i].y2) - query(s[i].y1 - 1);
      else
        sum[s[i].Id] += query(s[i].y2) - query(s[i].y1 - 1);
    }
  for (int i = 1; i <= q; ++i)
    printf("%d\n", ans[i] + (sum[i] < 0 ? 0 : sum[i] > 0 ? 1 : 2));
  return 0;
}
