#include <bits/stdc++.h>
using namespace std;
int n, m, q;
vector<int> G[200010];
vector<int> to[200010];
vector<pair<int, int> > que[200010];
int up[200010][21];
int dep[200010];
int par[200010][21];
int in[200010], out[200010];
int ans[200010];
int cnt;
void dfs(int x) {
  in[x] = ++cnt;
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    par[y][0] = x;
    dep[y] = dep[x] + 1;
    dfs(y);
  }
  out[x] = cnt;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; i >= 0; i--)
    if (dep[par[x][i]] >= dep[y]) x = par[x][i];
  if (x == y) return x;
  for (int i = 20; i >= 0; i--)
    if (par[x][i] != par[y][i]) x = par[x][i], y = par[y][i];
  return par[x][0];
}
void update(int x, int y) {
  if (dep[y] < dep[up[x][0]]) up[x][0] = y;
}
int calup(int x) {
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    update(x, calup(y));
  }
  return up[x][0];
}
bool insubt(int x, int y) { return (in[y] >= in[x] && in[y] <= out[x]); }
pair<int, int> calc(int x, int y) {
  int res = 0;
  for (int i = 20; i >= 0; i--) {
    if (!insubt(up[x][i], y)) x = up[x][i], res += (1 << i);
  }
  return make_pair(x, res);
}
int sum[200010];
void add(int x, int v) {
  for (int i = x; i <= n; i += i & -i) sum[i] += v;
}
int query(int x) {
  int res = 0;
  for (int i = x; i; i -= i & -i) res += sum[i];
  return res;
}
int chg[200010];
void solve(int x) {
  for (int i = 0; i < que[x].size(); i++) {
    int y = que[x][i].first, id = que[x][i].second;
    chg[id] = query(out[y]) - query(in[y] - 1);
  }
  for (int i = 0; i < to[x].size(); i++) {
    int y = to[x][i];
    add(in[y], 1);
  }
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    solve(y);
  }
  for (int i = 0; i < que[x].size(); i++) {
    int y = que[x][i].first, id = que[x][i].second;
    if (chg[id] != query(out[y]) - query(in[y] - 1)) ans[id]--;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    G[x].push_back(i);
  }
  dep[0] = -1;
  dfs(1);
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) par[j][i] = par[par[j][i - 1]][i - 1];
  }
  for (int i = 1; i <= n; i++) up[i][0] = i;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int xy = lca(x, y);
    update(x, xy);
    update(y, xy);
    to[x].push_back(y);
    to[y].push_back(x);
  }
  calup(1);
  for (int i = 1; i <= 20; i++) {
    for (int j = 1; j <= n; j++) up[j][i] = up[up[j][i - 1]][i - 1];
  }
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int xy = lca(x, y);
    if (!insubt(up[x][20], xy) || !insubt(up[y][20], xy)) {
      ans[i] = -1;
      continue;
    }
    pair<int, int> r1 = calc(x, xy);
    pair<int, int> r2 = calc(y, xy);
    x = r1.first;
    y = r2.first;
    ans[i] = r1.second + r2.second;
    if (x == xy || y == xy)
      ans[i]++;
    else {
      ans[i] += 2;
      que[x].push_back(make_pair(y, i));
    }
  }
  solve(1);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
