#include <bits/stdc++.h>
using namespace std;
vector<int> G[200050], bs[200050];
vector<pair<int, int> > ask[200050];
int p[200050][19], g[200050][19];
int dep[200050] = {0};
int lowet[200050], ans[200050], sum[200050];
int tre[400050];
int a[400050], st[200050], ed[200050];
int n, m, qus, tim = 0;
void dfs(int x) {
  a[++tim] = x;
  st[x] = tim;
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    dfs(y);
  }
  a[++tim] = x;
  ed[x] = tim;
}
void lcainit(int x, int fa) {
  dep[x] = dep[fa] + 1;
  p[x][0] = fa;
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    if (y == fa) continue;
    lcainit(y, x);
  }
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int i = 18; i >= 0; i--) {
    if (dep[x] <= dep[y] - (1 << i)) {
      y = p[y][i];
    }
  }
  if (x == y) return x;
  for (int i = 18; i >= 0; i--) {
    if (p[x][i] == p[y][i]) continue;
    x = p[x][i], y = p[y][i];
  }
  return p[x][0];
}
void update(int x, int y) {
  if (x == y) return;
  if (dep[lowet[x]] == 0 || dep[y] < dep[lowet[x]]) lowet[x] = y;
}
void calclow(int x) {
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    calclow(y);
    if (lowet[y]) update(x, lowet[y]);
  }
}
int query(int x) {
  int ans = 0;
  while (x) {
    ans += tre[x];
    x -= (x & -x);
  }
  return ans;
}
void change(int x, int y) {
  for (; x <= n + n; x += (x & -x)) tre[x] += y;
}
void worklow(int x) {
  g[x][0] = lowet[x];
  for (int i = 1; i <= 18; i++) {
    g[x][i] = g[g[x][i - 1]][i - 1];
  }
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    worklow(y);
  }
}
pair<int, int> go(int x, int to) {
  int ans = 0;
  for (int i = 18; i >= 0; i--) {
    if (dep[g[x][i]] > dep[to]) {
      x = g[x][i];
      ans += (1 << i);
    }
  }
  if (dep[g[x][0]] == 0)
    return make_pair(-2, 0);
  else
    return make_pair(ans, x);
}
void solve(int x) {
  for (int i = 0; i < ask[x].size(); i++) {
    int y = ask[x][i].first, id = ask[x][i].second;
    sum[id] = query(ed[y]) - query(st[y]);
  }
  for (int i = 0; i < bs[x].size(); i++) {
    int y = bs[x][i];
    change(ed[y], 1);
  }
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    solve(y);
  }
  for (int i = 0; i < ask[x].size(); i++) {
    int y = ask[x][i].first, id = ask[x][i].second;
    if (sum[id] == query(ed[y]) - query(st[y])) ans[id]++;
  }
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int f;
    scanf("%d", &f);
    G[f].push_back(i);
  }
  lcainit(1, 0);
  dfs(1);
  for (int i = 1; i <= 18; i++) {
    for (int j = 1; j <= n; j++) {
      p[j][i] = p[p[j][i - 1]][i - 1];
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    bs[x].push_back(y);
    bs[y].push_back(x);
    int z = lca(x, y);
    update(x, z);
    update(y, z);
  }
  calclow(1);
  worklow(1);
  cin >> qus;
  int x, y;
  for (int i = 1; i <= qus; i++) {
    scanf("%d%d", &x, &y);
    int z = lca(x, y);
    if (x == z) {
      ans[i] = go(y, z).first + 1;
      continue;
    }
    if (y == z) {
      ans[i] = go(x, z).first + 1;
      continue;
    }
    pair<int, int> gx = go(x, z);
    pair<int, int> gy = go(y, z);
    int nx = gx.first, ny = gy.first;
    int px = gx.second, py = gy.second;
    if (nx < 0 || ny < 0)
      ans[i] = -1;
    else {
      ans[i] = nx + ny + 1;
      ask[px].push_back(make_pair(py, i));
    }
  }
  solve(1);
  for (int i = 1; i <= qus; i++) printf("%d\n", ans[i]);
  return 0;
}
