#include <bits/stdc++.h>
using namespace std;
const int N = 200005;
const int M = 15000005;
int ls[M], rs[M];
int n, fa[N][20], Fa[N][20];
int dep[N], dfn[N], ed[N];
int rt[N], nd, m, Q;
vector<int> e[N];
vector<int> vec[N];
pair<int, int> t[N];
void insert(int &k, int l, int r, int p) {
  if (!k) k = ++nd;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (p <= mid)
    insert(ls[k], l, mid, p);
  else
    insert(rs[k], mid + 1, r, p);
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  int k = ++nd;
  ls[k] = merge(ls[x], ls[y]);
  rs[k] = merge(rs[x], rs[y]);
  return k;
}
int ask(int k, int l, int r, int x, int y) {
  if (!k) return 0;
  if (x <= l && r <= y) return 1;
  int mid = (l + r) / 2, ans = 0;
  if (x <= mid) ans |= ask(ls[k], l, mid, x, y);
  if (y > mid) ans |= ask(rs[k], mid + 1, r, x, y);
  return ans;
}
void dfs(int x) {
  dfn[x] = ++*dfn;
  for (auto i : e[x]) dfs(i);
  ed[x] = *dfn;
}
void dfs2(int x) {
  for (auto i : vec[x]) insert(rt[x], 1, n, dfn[i]);
  for (auto i : e[x]) {
    dfs2(i);
    t[x] = min(t[x], t[i]);
    rt[x] = merge(rt[x], rt[i]);
  }
  if (t[x].first >= dep[x])
    Fa[x][0] = x;
  else
    Fa[x][0] = t[x].second;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int tmp = dep[x] - dep[y];
  for (int i = (int)(0); i <= (int)(18); i++)
    if (tmp & (1 << i)) x = fa[x][i];
  for (int i = (int)(18); i >= (int)(0); i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return x == y ? x : fa[x][0];
}
int main() {
  scanf("%d", &n);
  dep[1] = 1;
  for (int i = (int)(1); i <= (int)(n); i++)
    t[i] = pair<int, int>(1 << 30, 1 << 30);
  for (int i = (int)(2); i <= (int)(n); i++) {
    scanf("%d", &fa[i][0]);
    dep[i] = dep[fa[i][0]] + 1;
    e[fa[i][0]].push_back(i);
  }
  dfs(1);
  for (int i = (int)(1); i <= (int)(18); i++)
    for (int j = (int)(1); j <= (int)(n); j++)
      fa[j][i] = fa[fa[j][i - 1]][i - 1];
  scanf("%d", &m);
  for (int i = (int)(1); i <= (int)(m); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int L = LCA(x, y);
    t[x] = min(t[x], pair<int, int>(dep[L], L));
    t[y] = min(t[y], pair<int, int>(dep[L], L));
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  dfs2(1);
  for (int i = (int)(1); i <= (int)(18); i++)
    for (int j = (int)(1); j <= (int)(n); j++)
      Fa[j][i] = Fa[Fa[j][i - 1]][i - 1];
  scanf("%d", &Q);
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    int L = LCA(x, y);
    if (dep[Fa[x][18]] > dep[L] || dep[Fa[y][18]] > dep[L])
      puts("-1");
    else {
      int ans = 0;
      for (int i = (int)(17); i >= (int)(0); i--)
        if (dep[Fa[x][i]] > dep[L]) x = Fa[x][i], ans += 1 << i;
      for (int i = (int)(17); i >= (int)(0); i--)
        if (dep[Fa[y][i]] > dep[L]) y = Fa[y][i], ans += 1 << i;
      if (x == L || y == L)
        ans++;
      else if (ask(rt[x], 1, n, dfn[y], ed[y]))
        ans++;
      else
        ans += 2;
      printf("%d\n", ans);
    }
  }
}
