#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5, L = 20;
vector<int> v[N], up[N], w[N], mem[N];
vector<pair<int, int>> wh[N];
int tin[N], tout[N], p[N][L], lw[N][L], h[N], t[N], ans[N], sub[N];
int timer = 1;
bool bad[N];
void add(int x) {
  for (; x < N; x |= x + 1) t[x]++;
}
int que(int x) {
  int s = 0;
  for (; x >= 0; x = (x & (x + 1)) - 1) s += t[x];
  return s;
}
void dfs(int node, int anc) {
  p[node][0] = anc;
  for (int i = 1; i < L; i++) p[node][i] = p[p[node][i - 1]][i - 1];
  tin[node] = timer++;
  for (int to : v[node]) {
    dfs(to, node);
  }
  tout[node] = timer;
}
int deep(int node) {
  lw[node][0] = -1;
  for (int to : v[node]) {
    h[to] = h[node] + 1;
    int a = deep(to);
    if (a != -1 && (lw[node][0] == -1 || h[lw[node][0]] > h[a]))
      lw[node][0] = a;
  }
  for (int a : up[node]) {
    if (lw[node][0] == -1 || h[lw[node][0]] > h[a]) lw[node][0] = a;
  }
  if (h[lw[node][0]] >= h[node]) lw[node][0] = -1;
  return lw[node][0];
}
void inward(int node) {
  for (int i = 1; i < L; i++) {
    if (lw[node][i - 1] == -1)
      lw[node][i] = -1;
    else
      lw[node][i] = lw[lw[node][i - 1]][i - 1];
  }
  for (int to : v[node]) inward(to);
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  for (int i = L - 1; i >= 0; i--) {
    if (!upper(p[a][i], b)) a = p[a][i];
  }
  return p[a][0];
}
int handle(int a, int b, int c) {
  if (a == b) return a;
  ans[c]++;
  for (int i = L - 1; i >= 0; i--) {
    if (lw[a][i] != -1 && !upper(lw[a][i], b)) {
      a = lw[a][i];
      ans[c] += (1 << i);
    }
  }
  if (lw[a][0] == -1) bad[c] = 1;
  return a;
}
void walk(int node) {
  mem[node].resize(wh[node].size());
  for (int i = 0; i < wh[node].size(); i++) {
    auto g = wh[node][i];
    mem[node][i] = que(tout[g.first] - 1) - que(tin[g.first] - 1);
  }
  for (auto g : w[node]) {
    add(tin[g]);
  }
  for (int to : v[node]) walk(to);
  for (int i = 0; i < wh[node].size(); i++) {
    auto g = wh[node][i];
    if (mem[node][i] != que(tout[g.first] - 1) - que(tin[g.first] - 1))
      sub[g.second] = 1;
  }
}
int main() {
  int n, m, q;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    v[p - 1].push_back(i);
  }
  dfs(0, 0);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int x, y, l;
    scanf("%d%d", &x, &y);
    x--, y--;
    l = lca(x, y);
    if (l != x) up[x].push_back(l);
    if (l != y) up[y].push_back(l);
    if (l != x && l != y) {
      w[x].push_back(y);
      w[y].push_back(x);
    }
  }
  memset(lw, -1, sizeof(lw));
  deep(0);
  inward(0);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int x, y, l;
    scanf("%d%d", &x, &y);
    x--, y--;
    l = lca(x, y);
    x = handle(x, l, i);
    y = handle(y, l, i);
    if (!bad[i] && x != l && y != l) {
      wh[x].emplace_back(y, i);
      wh[y].emplace_back(x, i);
    }
  }
  walk(0);
  for (int i = 0; i < q; i++) {
    if (bad[i])
      printf("-1\n");
    else
      printf("%d\n", ans[i] - sub[i]);
  }
  return 0;
}
