#include <bits/stdc++.h>
const int N = 200000;
const int LG = 18;
int n, m, q, p[LG][N], up[LG][N], in[N], out[N], d[N], b[N], ans[N];
std::vector<int> g[N], next[N];
std::vector<std::pair<int, int> > query[N];
void dfs1(int v) {
  static int t = 0;
  in[v] = t++;
  for (int i = 0; i < (int)g[v].size(); ++i) {
    d[g[v][i]] = d[v] + 1;
    dfs1(g[v][i]);
  }
  out[v] = t;
}
bool parent(int u, int v) { return in[u] <= in[v] && out[u] >= out[v]; }
int lca(int u, int v) {
  if (parent(v, u)) return v;
  for (int i = LG - 1; i >= 0; --i)
    if (!parent(p[i][v], u)) v = p[i][v];
  return p[0][v];
}
void apply(int &u, int v) {
  if (d[u] > d[v]) u = v;
}
void dfs2(int v) {
  for (int i = 0; i < (int)g[v].size(); ++i) {
    dfs2(g[v][i]);
    apply(up[0][v], up[0][g[v][i]]);
  }
}
int dist(int u, int v) {
  if (u == v) return 0;
  int r = 0;
  for (int i = LG - 1; i >= 0; --i)
    if (d[up[i][u]] > d[v]) {
      u = up[i][u];
      r += 1 << i;
    }
  return r + 1;
}
int go(int v, int k) {
  for (int i = LG - 1; i >= 0; --i)
    if (1 << i <= k) {
      v = up[i][v];
      k -= 1 << i;
    }
  return v;
}
void add(int i) {
  while (i < n) {
    ++b[i];
    i |= i + 1;
  }
}
int get(int i) {
  int s = 0;
  while (i >= 0) {
    s += b[i];
    i = (i & i + 1) - 1;
  }
  return s;
}
void dfs3(int v) {
  std::vector<int> sum(query[v].size());
  for (int i = 0; i < (int)query[v].size(); ++i)
    sum[i] = get(out[query[v][i].first] - 1) - get(in[query[v][i].first] - 1);
  for (int i = 0; i < (int)next[v].size(); ++i) add(in[next[v][i]]);
  for (int i = 0; i < (int)g[v].size(); ++i) dfs3(g[v][i]);
  for (int i = 0; i < (int)query[v].size(); ++i)
    if (sum[i] !=
        get(out[query[v][i].first] - 1) - get(in[query[v][i].first] - 1))
      --ans[query[v][i].second];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d", p[0] + i);
    --p[0][i];
    g[p[0][i]].push_back(i);
  }
  for (int j = 1; j < LG; ++j)
    for (int i = 0; i < n; ++i) p[j][i] = p[j - 1][p[j - 1][i]];
  dfs1(0);
  std::iota(up[0], up[0] + n, 0);
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    if (in[a] > in[b]) std::swap(a, b);
    next[a].push_back(b);
    int l = lca(a, b);
    apply(up[0][a], l);
    apply(up[0][b], l);
  }
  dfs2(0);
  for (int j = 1; j < LG; ++j)
    for (int i = 0; i < n; ++i) up[j][i] = up[j - 1][up[j - 1][i]];
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    if (in[u] > in[v]) std::swap(u, v);
    int l = lca(u, v);
    int d1 = dist(u, l), d2 = dist(v, l);
    ans[i] = d1 + d2;
    if (ans[i] > n)
      ans[i] = -1;
    else if (d1 && d2) {
      int last1 = go(u, d1 - 1), last2 = go(v, d2 - 1);
      query[last1].push_back(std::make_pair(last2, i));
    }
  }
  dfs3(0);
  for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
  return 0;
}
