#include <bits/stdc++.h>
using namespace std;
template <typename T>
bool chkmax(T &a, T b) {
  return (a < b) ? a = b, 1 : 0;
}
template <typename T>
bool chkmin(T &a, T b) {
  return (a > b) ? a = b, 1 : 0;
}
inline int read() {
  int x = 0, fh = 1;
  char ch = getchar();
  for (; !isdigit(ch); ch = getchar())
    if (ch == '-') fh = -1;
  for (; isdigit(ch); ch = getchar()) x = (x << 1) + (x << 3) + (ch ^ '0');
  return x * fh;
}
int n, m, q;
int dp[200005][20];
vector<int> G[200005];
int cnt, dep[200005], dfn[200005], ed[200005], fa[200005][20];
void dfs(int x) {
  dfn[x] = ++cnt;
  for (int v : G[x])
    if (v != fa[x][0]) fa[v][0] = x, dp[v][0] = dep[v] = dep[x] + 1, dfs(v);
  ed[x] = cnt;
}
int A[200005], B[200005];
int a[200005], b[200005];
int c[200005], s[200005];
vector<int> tr[200005];
int t[200005];
int lowbit(int x) { return x & (-x); }
void add(int x) {
  for (; x <= 200000; x += lowbit(x)) ++t[x];
}
int sum(int x) {
  int res = 0;
  for (; x; x -= lowbit(x)) res += t[x];
  return res;
}
int LCA(int x, int y) {
  int k = dep[x] - dep[y], i;
  if (k < 0) k = -k, swap(x, y);
  for (i = 0; k; k >>= 1, ++i)
    if (k & 1) x = fa[x][i];
  if (x == y) return x;
  for (int i = 18; i--;)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void DP(int x) {
  for (int v : G[x]) {
    if (v == fa[x][0]) continue;
    DP(v), dp[x][0] = min(dp[x][0], dp[v][0]);
  }
}
int getans(int x, int y) {
  for (int i = 0; y; y >>= 1, ++i)
    if (y & 1) x = fa[x][i];
  return x;
}
void getdp(int x) {
  for (int v : tr[x]) {
    if (v > 0) s[v] -= sum(ed[b[v]]) - sum(dfn[b[v]] - 1);
  }
  for (int v : tr[x]) {
    if (v < 0) add(dfn[-v]);
  }
  for (int v : G[x])
    if (v != fa[x][0]) getdp(v);
  for (int v : tr[x]) {
    if (v > 0) s[v] += sum(ed[b[v]]) - sum(dfn[b[v]] - 1);
  }
}
int main() {
  n = read();
  for (int i = (2), _end_ = (int)(n); i <= _end_; ++i) {
    int ff = read();
    G[ff].push_back(i);
    G[i].push_back(ff);
  }
  dfs(1);
  for (int l = (1), _end_ = (int)(17); l <= _end_; ++l)
    for (int i = (1), _end_ = (int)(n); i <= _end_; ++i)
      fa[i][l] = fa[fa[i][l - 1]][l - 1];
  m = read();
  for (int i = (1), _end_ = (int)(m); i <= _end_; ++i) {
    A[i] = read(), B[i] = read();
    int lca = LCA(A[i], B[i]);
    dp[A[i]][0] = min(dp[A[i]][0], dep[lca]);
    dp[B[i]][0] = min(dp[B[i]][0], dep[lca]);
    tr[A[i]].push_back(-B[i]);
    tr[B[i]].push_back(-A[i]);
  }
  DP(1);
  for (int i = (1), _end_ = (int)(n); i <= _end_; ++i)
    dp[i][0] = getans(i, dep[i] - dp[i][0]);
  for (int j = (1), _end_ = (int)(17); j <= _end_; ++j)
    for (int i = (1), _end_ = (int)(n); i <= _end_; ++i)
      dp[i][j] = dp[dp[i][j - 1]][j - 1];
  q = read();
  for (int i = (1), _end_ = (int)(q); i <= _end_; ++i) {
    a[i] = read();
    b[i] = read();
    int lca = LCA(a[i], b[i]);
    if (b[i] == lca) swap(a[i], b[i]);
    if (a[i] == lca) {
      for (int j = 18; j--;)
        if (dep[dp[b[i]][j]] > dep[lca]) b[i] = dp[b[i]][j], c[i] += 1 << j;
      if (dep[dp[b[i]][0]] > dep[lca]) c[i] = -1;
      continue;
    }
    for (int j = 18; j--;)
      if (dep[dp[a[i]][j]] > dep[lca]) a[i] = dp[a[i]][j], c[i] += 1 << j;
    for (int j = 18; j--;)
      if (dep[dp[b[i]][j]] > dep[lca]) b[i] = dp[b[i]][j], c[i] += 1 << j;
    if (dep[dp[a[i]][0]] > dep[lca] || dep[dp[b[i]][0]] > dep[lca])
      c[i] = -1;
    else
      ++c[i], tr[a[i]].push_back(i);
  }
  getdp(1);
  for (int i = (1), _end_ = (int)(q); i <= _end_; ++i) {
    if (c[i] + 1 - bool(s[i]) == 0)
      printf("-1\n");
    else
      printf("%d\n", c[i] + 1 - bool(s[i]));
  }
  return 0;
}
