#include <bits/stdc++.h>
using namespace std;
const long long mod = 1000000007;
long long powmod(long long a, long long b) {
  long long res = 1;
  a %= mod;
  assert(b >= 0);
  for (; b; b >>= 1) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
  }
  return res;
}
long long gcd(long long a, long long b) { return b ? gcd(b, a % b) : a; }
const int N = 201000;
int p[N][20], x, y, n, m, q, dep[N], go[N][20], mind[N][20];
set<pair<int, int> > pool[N];
set<pair<int, int> >* ins[N];
vector<int> e[N];
int lca(int u, int v) {
  if (dep[u] > dep[v]) swap(u, v);
  for (int i = 18 - 1; i >= 0; i--)
    if (dep[p[v][i]] >= dep[u]) v = p[v][i];
  if (u == v) return u;
  for (int i = 18 - 1; i >= 0; i--)
    if (p[v][i] != p[u][i]) u = p[u][i], v = p[v][i];
  return p[u][0];
}
void upd(int& a, int b) {
  if (dep[b] < dep[a]) a = b;
}
int tot, l[N], r[N], c[N], vis[N], cur[N], ret[N];
void dfs(int u, int f) {
  l[u] = ++tot;
  for (auto v : e[u]) dfs(v, u);
  r[u] = tot;
}
void modify(int x, int s) {
  for (; x <= n; x += x & -x) c[x] += s;
}
int query(int x) {
  int s = 0;
  for (; x; x -= x & -x) s += c[x];
  return s;
}
vector<pair<int, pair<int, int> > > evt;
int main() {
  scanf("%d", &n);
  dep[1] = 1;
  for (int i = 2; i < n + 1; i++) {
    scanf("%d", &x);
    p[i][0] = x;
    dep[i] = dep[x] + 1;
    e[x].push_back(i);
  }
  dfs(1, 0);
  for (int j = 1; j < 18; j++)
    for (int i = 1; i < n + 1; i++) p[i][j] = p[p[i][j - 1]][j - 1];
  scanf("%d", &m);
  for (int i = 1; i < n + 1; i++) go[i][0] = i;
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &x, &y);
    int w = lca(x, y);
    upd(go[x][0], w);
    upd(go[y][0], w);
    evt.push_back(make_pair(l[x], make_pair(-1e9, l[y])));
    evt.push_back(make_pair(l[y], make_pair(-1e9, l[x])));
  }
  for (int i = n + 1 - 1; i >= 2; i--) upd(go[p[i][0]][0], go[i][0]);
  for (int k = 1; k < 18; k++)
    for (int i = 1; i <= n; i++) {
      go[i][k] = go[i][k - 1];
      upd(go[i][k], go[go[i][k - 1]][k - 1]);
    }
  scanf("%d", &q);
  for (int i = 1; i < q + 1; i++) {
    scanf("%d%d", &x, &y);
    int w = lca(x, y);
    if (dep[go[x][18 - 1]] > dep[w] || dep[go[y][18 - 1]] > dep[w]) {
      ret[i] = -1;
      continue;
    }
    for (int j = 18 - 1; j >= 0; j--)
      if (dep[go[x][j]] > dep[w]) {
        x = go[x][j];
        ret[i] += (1 << j);
      }
    for (int j = 18 - 1; j >= 0; j--)
      if (dep[go[y][j]] > dep[w]) {
        y = go[y][j];
        ret[i] += (1 << j);
      }
    if (w == x || w == y) {
      ret[i]++;
      continue;
    }
    vis[i] = 1;
    evt.push_back(make_pair(l[x] - 1, make_pair(i, l[y] - 1)));
    evt.push_back(make_pair(l[x] - 1, make_pair(-i, r[y])));
    evt.push_back(make_pair(r[x], make_pair(-i, l[y] - 1)));
    evt.push_back(make_pair(r[x], make_pair(i, r[y])));
  }
  sort((evt).begin(), (evt).end());
  for (auto p : evt) {
    int id = p.second.first, y = p.second.second;
    if (id < -q) {
      modify(y, 1);
    } else {
      if (id > 0)
        cur[id] += query(y);
      else
        cur[-id] -= query(y);
    }
  }
  for (int i = 1; i < q + 1; i++)
    if (vis[i]) {
      if (cur[i])
        ret[i]++;
      else
        ret[i] += 2;
    }
  for (int i = 1; i < q + 1; i++) printf("%d\n", ret[i]);
}
