#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 5;
const int inf = 0x3f3f3f3f;
int n, m, Q, cnt, val, x, y, ind;
int deep[N], in[N], out[N], last[N];
int first[N], ans[N], tr[N];
int fa[N][20], low[N][20];
bool ok[N];
vector<int> a[N], b[N];
struct edge {
  int to, next;
} e[N];
struct chain {
  int x, y, t;
} c[N], q[N];
int read() {
  int x = 0, f = 1;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * f;
}
void ins(int u, int v) {
  e[++cnt] = (edge){v, first[u]};
  first[u] = cnt;
}
void dfs(int x) {
  in[x] = ++ind;
  for (int i = 1; (1 << i) <= deep[x]; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = first[x]; i; i = e[i].next) {
    deep[e[i].to] = deep[x] + 1;
    dfs(e[i].to);
  }
  out[x] = ind;
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  int d = deep[x] - deep[y];
  for (int i = 0; (1 << i) <= d; i++)
    if ((1 << i) & d) x = fa[x][i];
  if (x == y) return x;
  for (int i = 17; i >= 0; i--)
    if ((1 << i) <= deep[x] && fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void dfslow(int x) {
  for (int i = first[x]; i; i = e[i].next) {
    int to = e[i].to;
    dfslow(to);
    if (deep[low[to][0]] < deep[low[x][0]]) low[x][0] = low[to][0];
  }
}
int find(int x, int t) {
  if (deep[low[x][17]] > deep[t]) {
    val = -inf;
    return -1;
  }
  if (x == t) {
    val = -1;
    return 0;
  }
  val = 0;
  for (int i = 17; i >= 0; i--)
    if (deep[low[x][i]] > deep[t]) x = low[x][i], val |= (1 << i);
  return x;
}
int lowbit(int x) { return x & (-x); }
void add(int x, int v) {
  for (; x <= n; x += lowbit(x)) tr[x] += v;
}
int query(int x) {
  int ans = 0;
  for (; x; x -= lowbit(x)) ans += tr[x];
  return ans;
}
void work(int x) {
  for (int sz = b[x].size(), i = 0; i < sz; i++) {
    int t = b[x][i];
    last[t] = query(out[q[t].y]) - query(in[q[t].y] - 1);
  }
  for (int sz = a[x].size(), i = 0; i < sz; i++) add(in[a[x][i]], 1);
  for (int i = first[x]; i; i = e[i].next) work(e[i].to);
  for (int sz = b[x].size(), i = 0; i < sz; i++) {
    int t = b[x][i];
    if (query(out[q[t].y]) - query(in[q[t].y] - 1) != last[t]) ok[t] = true;
  }
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) fa[i][0] = read(), ins(fa[i][0], i);
  dfs(1);
  for (int i = 1; i <= n; i++) low[i][0] = i;
  m = read();
  for (int i = 1; i <= m; i++) {
    c[i].x = read();
    c[i].y = read();
    c[i].t = lca(c[i].x, c[i].y);
    if (deep[c[i].t] < deep[low[c[i].x][0]]) low[c[i].x][0] = c[i].t;
    if (deep[c[i].t] < deep[low[c[i].y][0]]) low[c[i].y][0] = c[i].t;
    a[c[i].x].push_back(c[i].y);
    a[c[i].y].push_back(c[i].x);
  }
  dfslow(1);
  for (int t = 1; t <= n; t++)
    for (int i = 1; i <= 17; i++) low[t][i] = low[low[t][i - 1]][i - 1];
  Q = read();
  for (int i = 1; i <= Q; i++) {
    q[i].x = read();
    q[i].y = read();
    q[i].t = lca(q[i].x, q[i].y);
    ans[i] = 2;
    x = find(q[i].x, q[i].t);
    ans[i] += val;
    y = find(q[i].y, q[i].t);
    ans[i] += val;
    if (x > 0 && y > 0) {
      q[i].x = x;
      q[i].y = y;
      b[x].push_back(i);
    }
  }
  work(1);
  for (int i = 1; i <= Q; i++)
    if (ok[i]) ans[i]--;
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i] < 0 ? -1 : ans[i]);
  return 0;
}
