#include <bits/stdc++.h>
using namespace std;
const int MN = 200005, P2 = (1 << 19), MTS = 2 * P2 + 5, inf = 1000000005,
          mod = 1000000007;
const int LG = 20;
const long long INF = 1000000000000000005LL;
pair<int, int> min_dep[LG][MN];
int hop[LG][MN];
int pre[MN], post[MN], dep[MN];
vector<int> from[MN], G[MN];
vector<pair<int, int> > zap[MN];
int bus_a[MN], bus_b[MN], bus_lca[MN], ans[MN];
int suma_przed[MN], used[MN];
int T[MTS];
int licznik, n, m;
void add(int v, int x) {
  x += P2;
  while (x) {
    T[x] += v;
    x >>= 1;
  }
}
int sum(int a, int b) {
  a += P2, b += P2;
  int ret = 0;
  while (a < b) {
    if (a & 1) ret += T[a++];
    if (!(b & 1)) ret += T[b--];
    a >>= 1, b >>= 1;
  }
  if (a == b) ret += T[a];
  return ret;
}
void dfs_prep(int x, int d) {
  dep[x] = d;
  pre[x] = ++licznik;
  for (auto v : G[x])
    if (!pre[v]) {
      hop[0][v] = x;
      dfs_prep(v, d + 1);
    }
  post[x] = ++licznik;
}
void dfs_md(int x) {
  min_dep[0][x] = {dep[x], x};
  for (auto b : from[x])
    min_dep[0][x] = min(min_dep[0][x], {dep[bus_lca[b]], bus_lca[b]});
  for (auto v : G[x])
    if (!min_dep[0][v].first) {
      dfs_md(v);
      min_dep[0][x] = min(min_dep[0][x], min_dep[0][v]);
    }
}
void dfs_opt(int x) {
  used[x] = 1;
  for (auto z : zap[x]) suma_przed[z.second] = sum(pre[z.first], post[z.first]);
  for (auto b : from[x]) {
    int to = (x == bus_a[b] ? bus_b[b] : bus_a[b]);
    add(1, pre[to]);
  }
  for (auto v : G[x])
    if (!used[v]) dfs_opt(v);
  for (auto z : zap[x])
    if (suma_przed[z.second] != sum(pre[z.first], post[z.first]))
      --ans[z.second];
}
bool child(int a, int b) { return (pre[a] >= pre[b] && post[a] <= post[b]); }
int lca(int a, int b) {
  if (child(a, b)) return b;
  if (child(b, a)) return a;
  int s = LG - 1;
  while (s >= 0) {
    if (child(b, hop[s][a]))
      --s;
    else
      a = hop[s][a];
  }
  a = hop[0][a];
  return a;
}
pair<int, int> buses_up(int x, int y) {
  int s = LG - 1, ret = 0;
  while (s >= 0) {
    if (min_dep[s][x].first > dep[y]) {
      ret += (1 << s);
      if (ret > m) return {inf, inf};
      x = min_dep[s][x].second;
    } else {
      --s;
    }
  }
  if (dep[x] > dep[y]) ++ret;
  if (ret > m) return {inf, inf};
  return {ret, x};
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
    G[i].push_back(p);
  }
  dfs_prep(1, 1);
  hop[0][1] = 1;
  for (int i = 1; i < LG; ++i)
    for (int j = 1; j <= n; ++j) hop[i][j] = hop[i - 1][hop[i - 1][j]];
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int a, b, l;
    scanf("%d%d", &a, &b);
    l = lca(a, b);
    bus_a[i] = a;
    bus_b[i] = b;
    bus_lca[i] = l;
    from[a].push_back(i);
    from[b].push_back(i);
  }
  dfs_md(1);
  for (int i = 1; i < LG; ++i)
    for (int j = 1; j <= n; ++j)
      min_dep[i][j] = min_dep[i - 1][min_dep[i - 1][j].second];
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (child(u, v)) {
      ans[i] = buses_up(u, v).first;
    } else if (child(v, u)) {
      ans[i] = buses_up(v, u).first;
    } else {
      int l = lca(u, v);
      pair<int, int> le = buses_up(u, l), pr = buses_up(v, l);
      if (max(le.first, pr.first) == inf) {
        ans[i] = inf;
        continue;
      }
      ans[i] = le.first + pr.first;
      zap[le.second].push_back({pr.second, i});
    }
  }
  dfs_opt(1);
  for (int i = 1; i <= q; ++i)
    if (ans[i] > 1e8)
      printf("-1\n");
    else
      printf("%d\n", ans[i]);
}
