#include <bits/stdc++.h>
using namespace std;
const int N = 200010;
vector<int> ver[N], bus[N];
vector<pair<int, int> > query[N];
int fa[N][18], d[N];
int a[2 * N], st[N], ed[N];
int lowest[N], g[N][18];
int c[2 * N], ans[N], sum[N];
int n, m, q, t;
void add(int x, int y) { ver[x].push_back(y); }
void dfs(int x) {
  a[++t] = x, st[x] = t;
  for (int i = 0; i < ver[x].size(); i++) {
    int y = ver[x][i];
    d[y] = d[x] + 1;
    fa[y][0] = x;
    for (int j = 1; j < 18; j++) fa[y][j] = fa[fa[y][j - 1]][j - 1];
    dfs(y);
  }
  a[++t] = x, ed[x] = t;
}
int lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = 17; i >= 0; i--)
    if (d[fa[x][i]] >= d[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 17; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void update_lowest(int x, int anc) {
  if (x == anc) return;
  if (lowest[x] == 0 || d[anc] < d[lowest[x]]) lowest[x] = anc;
}
void calc_lowest(int x) {
  for (int i = 0; i < ver[x].size(); i++) {
    int y = ver[x][i];
    calc_lowest(y);
    if (lowest[y]) update_lowest(x, lowest[y]);
  }
}
void binary_lifting_lowest(int x) {
  g[x][0] = lowest[x];
  for (int i = 1; i < 18; i++) g[x][i] = g[g[x][i - 1]][i - 1];
  for (int i = 0; i < ver[x].size(); i++) {
    int y = ver[x][i];
    binary_lifting_lowest(y);
  }
}
pair<int, int> go(int x, int y) {
  int ans = 0;
  for (int i = 17; i >= 0; i--)
    if (d[g[x][i]] > d[y]) x = g[x][i], ans += 1 << i;
  if (d[g[x][0]] == 0)
    return make_pair(-2, 0);
  else
    return make_pair(ans, x);
}
int ask(int x) {
  int ans = 0;
  for (; x; x -= x & -x) ans += c[x];
  return ans;
}
void change(int x, int y) {
  for (; x <= 2 * n; x += x & -x) c[x] += y;
}
void solve(int x) {
  for (int i = 0; i < query[x].size(); i++) {
    int y = query[x][i].first, id = query[x][i].second;
    sum[id] = ask(ed[y]) - ask(st[y]);
  }
  for (int i = 0; i < bus[x].size(); i++) {
    int y = bus[x][i];
    change(ed[y], 1);
  }
  for (int i = 0; i < ver[x].size(); i++) {
    int y = ver[x][i];
    solve(y);
  }
  for (int i = 0; i < query[x].size(); i++) {
    int y = query[x][i].first, id = query[x][i].second;
    if (sum[id] == ask(ed[y]) - ask(st[y])) ans[id]++;
  }
}
int main() {
  cin >> n;
  for (int i = 2, fa; i <= n; i++) {
    scanf("%d", &fa);
    add(fa, i);
  }
  d[1] = 1;
  dfs(1);
  cin >> m;
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    bus[x].push_back(y), bus[y].push_back(x);
    int z = lca(x, y);
    update_lowest(x, z), update_lowest(y, z);
  }
  calc_lowest(1);
  binary_lifting_lowest(1);
  cin >> q;
  for (int i = 1, x, y; i <= q; 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 lx = gx.first, ly = gy.first;
    int px = gx.second, py = gy.second;
    if (lx < 0 || ly < 0)
      ans[i] = -1;
    else {
      ans[i] = lx + ly + 1;
      query[px].push_back(make_pair(py, i));
    }
  }
  solve(1);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
}
