#include <bits/stdc++.h>
using namespace std;
const int maxn = 2e5 + 1000;
vector<int> side[maxn];
int size[maxn], dep[maxn], f[maxn][20], g[maxn][20];
int dfn[maxn], dfn_cnt;
int up[maxn];
void dfs1(int u, int fa) {
  dep[u] = dep[fa] + 1;
  f[u][0] = fa;
  dfn[u] = ++dfn_cnt;
  size[u] = 1;
  for (int i = 0; i < side[u].size(); i++) {
    int v = side[u][i];
    if (v == fa) continue;
    dfs1(v, u);
    size[u] += size[v];
  }
}
void dfs2(int u, int fa) {
  for (int i = 0; i < side[u].size(); i++) {
    int v = side[u][i];
    if (v == fa) continue;
    dfs2(v, u);
    if (dep[up[v]] < dep[up[u]]) up[u] = up[v];
  }
  g[u][0] = up[u];
}
int n;
void init1() {
  for (int i = (1), iend = (19); i <= iend; i++)
    for (int j = (1), jend = (n); j <= jend; j++)
      f[j][i] = f[f[j][i - 1]][i - 1];
}
void init2() {
  for (int i = (1), iend = (19); i <= iend; i++)
    for (int j = (1), jend = (n); j <= jend; j++)
      g[j][i] = g[g[j][i - 1]][i - 1];
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 19; i >= 0; i--)
    if (dep[f[u][i]] >= dep[v]) u = f[u][i];
  if (u == v) return u;
  for (int i = 19; i >= 0; i--)
    if (f[u][i] != f[v][i]) u = f[u][i], v = f[v][i];
  return f[u][0];
}
int ans[maxn], tmp[maxn];
struct Query {
  int idx, l, r, x, ty;
};
vector<Query> Q;
bool cmp(Query a, Query b) { return a.x < b.x; }
vector<int> po[maxn];
struct BIT {
  int c[maxn];
  void add(int u, int val) {
    for (int i = u; i < maxn; i += i & -i) c[i] += val;
  }
  int query(int u) {
    int ans = 0;
    for (int i = u; i; i -= i & -i) ans += c[i];
    return ans;
  }
  int seg(int l, int r) { return query(r) - query(l - 1); }
} t;
int main() {
  ios::sync_with_stdio(0);
  cin >> n;
  for (int i = (2), iend = (n); i <= iend; i++) {
    int v;
    cin >> v;
    side[i].push_back(v);
    side[v].push_back(i);
  }
  dfs1(1, 0);
  init1();
  for (int i = (1), iend = (n); i <= iend; i++) up[i] = i;
  int m;
  cin >> m;
  for (int i = (1), iend = (m); i <= iend; i++) {
    int a, b;
    cin >> a >> b;
    int l = lca(a, b);
    po[dfn[a]].push_back(dfn[b]);
    po[dfn[b]].push_back(dfn[a]);
    if (dep[l] < dep[up[a]]) up[a] = l;
    if (dep[l] < dep[up[b]]) up[b] = l;
  }
  dfs2(1, 0);
  init2();
  int q;
  cin >> q;
  for (int i = (1), iend = (q); i <= iend; i++) {
    int u, v;
    cin >> u >> v;
    int l = lca(u, v);
    for (int j = 19; j >= 0; j--)
      if (g[u][j] && g[u][j] != u && dep[g[u][j]] > dep[l])
        u = g[u][j], ans[i] += 1 << j;
    for (int j = 19; j >= 0; j--)
      if (g[v][j] && g[v][j] != v && dep[g[v][j]] > dep[l])
        v = g[v][j], ans[i] += 1 << j;
    if ((l == v && g[u][0] != u) || (l == u && g[v][0] != v))
      ans[i]++;
    else if (g[u][0] == u || g[v][0] == v)
      ans[i] = -1;
    else {
      if (dfn[u] - 1 >= 1)
        Q.push_back((Query){i, dfn[v], dfn[v] + size[v] - 1, dfn[u] - 1, -1});
      Q.push_back(
          (Query){i, dfn[v], dfn[v] + size[v] - 1, dfn[u] + size[u] - 1, 1});
      ans[i] += 2;
    }
  }
  sort(Q.begin(), Q.end(), cmp);
  int now = 0;
  for (int i = (1), iend = (n); i <= iend; i++) {
    for (int j = 0; j < po[i].size(); j++) t.add(po[i][j], 1);
    while (now < Q.size() && Q[now].x == i) {
      tmp[Q[now].idx] += Q[now].ty * t.seg(Q[now].l, Q[now].r);
      now++;
    }
  }
  for (int i = (1), iend = (q); i <= iend; i++)
    if (ans[i] != -1 && tmp[i]) ans[i]--;
  for (int i = (1), iend = (q); i <= iend; i++) cout << ans[i] << endl;
  return 0;
}
