#include <bits/stdc++.h>
using namespace std;
const int N = 200100;
const int N_FenTree = 400100;
const int M = 23;
int n, m, q, cnt, tme;
vector<int> bus[N], tmp[N];
vector<pair<int, int> > query[N];
int start[N], nxt[N * 2], to[N * 2], dep[N], fa[N][M], high[N][M], timein[N],
    timeout[N], ans[N];
void add(int x, int y) {
  nxt[++cnt] = start[x];
  to[cnt] = y;
  start[x] = cnt;
}
struct FenTree {
  int c1[N_FenTree], c2[N_FenTree];
  void ptAdd(int pos, int x) {
    for (int i = pos; i <= N_FenTree; i += i & (-i)) {
      c1[i] += x;
      c2[i] += x * pos;
    }
  }
  int ptSum(int pos) {
    int RV = 0;
    for (int i = pos; i; i -= i & (-i)) RV += (pos + 1) * c1[i] - c2[i];
    return RV;
  }
  void add(int l1, int l2, int val) {
    ptAdd(l1, val);
    ptAdd(l2 + 1, -val);
  }
  int sum(int l, int r) { return ptSum(r) - ptSum(l - 1); }
} tree;
void dfs(int cur) {
  timein[cur] = ++tme;
  for (int i = start[cur]; i; i = nxt[i])
    if (!dep[to[i]]) {
      dep[to[i]] = dep[cur] + 1;
      fa[to[i]][0] = cur;
      dfs(to[i]);
    }
  timeout[cur] = ++tme;
}
void dfs2(int cur) {
  for (int i = start[cur]; i; i = nxt[i])
    if (dep[to[i]] > dep[cur]) dfs2(to[i]);
  if (high[fa[cur][0]][0] == 0 || dep[high[cur][0]] < dep[high[fa[cur][0]][0]])
    high[fa[cur][0]][0] = high[cur][0];
}
void dfs3(int cur) {
  tmp[cur].resize(query[cur].size());
  for (int i = 0; i < query[cur].size(); i++)
    tmp[cur][i] =
        tree.sum(timein[query[cur][i].first], timeout[query[cur][i].first]);
  for (int i = start[cur]; i; i = nxt[i])
    if (dep[to[i]] > dep[cur]) dfs3(to[i]);
  for (int num : bus[cur]) tree.add(timein[num], timein[num], 1);
  for (int i = 0; i < query[cur].size(); i++)
    if (tmp[cur][i] !=
        tree.sum(timein[query[cur][i].first], timeout[query[cur][i].first]))
      ans[query[cur][i].second]--;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = M - 1; i >= 0; i--)
    if (fa[x][i] && dep[fa[x][i]] > dep[y]) x = fa[x][i];
  if (dep[x] != dep[y]) x = fa[x][0];
  for (int i = M - 1; i >= 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 cost(int x, int y) {
  if (x == y) return 0;
  int RV = 0;
  for (int i = M - 1; i >= 0; i--)
    if (high[x][i] && dep[high[x][i]] > dep[y]) x = high[x][i], RV += (1 << i);
  if (high[x][0] && dep[high[x][0]] <= dep[y]) return RV + 1;
  return -0x3f3f3f3f;
}
int get(int x, int cnt) {
  for (int i = 0; cnt; i++)
    if (cnt & 1 << i) cnt ^= 1 << i, x = high[x][i];
  return x;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    add(x, i);
    add(i, x);
  }
  dep[1] = 1;
  dep[0] = 0x3f3f3f3f;
  dfs(1);
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (timein[x] < timein[y])
      bus[x].push_back(y);
    else
      bus[y].push_back(x);
    int LCA = lca(x, y);
    if (!high[x][0] || dep[high[x][0]] > dep[LCA]) high[x][0] = LCA;
    if (!high[y][0] || dep[high[y][0]] > dep[LCA]) high[y][0] = LCA;
  }
  dfs2(1);
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= n; j++) high[j][i] = high[high[j][i - 1]][i - 1];
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int LCA = lca(x, y);
    int c1 = cost(x, LCA), c2 = cost(y, LCA);
    if (c1 < 0 || c2 < 0)
      ans[i] = -1;
    else {
      ans[i] = c1 + c2;
      if (x == LCA || y == LCA) continue;
      x = get(x, c1 - 1);
      y = get(y, c2 - 1);
      if (timein[x] < timein[y])
        query[x].push_back({y, i});
      else
        query[y].push_back({x, i});
    }
  }
  dfs3(1);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
