#include <bits/stdc++.h>
using namespace std;
int ls[401000 * 20], rs[401000 * 20], L[401000], R[401000], cnt, trcnt,
    rt[401000], root[401000], fa[401000][20], g[401000][20], dep[401000], size,
    g1[401000];
int siz[401000 * 20], tag[401000], n, m, o, p, q, i;
struct node {
  int to, next;
} e[401000];
pair<int, int> a[401000];
void add(int o, int p) {
  e[++size].to = p;
  e[size].next = g1[o];
  g1[o] = size;
}
void dfs1(int x) {
  L[x] = ++cnt;
  for (int i = 1; i <= 18; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int k = g1[x]; k; k = e[k].next) {
    int y = e[k].to;
    if (y != fa[x][0]) {
      dep[y] = dep[x] + 1;
      fa[y][0] = x;
      dfs1(y);
    }
  }
  R[x] = cnt;
}
void dfs2(int x) {
  int ret = tag[x];
  for (int k = g1[x]; k; k = e[k].next) {
    int y = e[k].to;
    if (y != fa[x][0]) {
      dfs2(y);
      if (dep[g[y][0]] < dep[ret]) ret = g[y][0];
    }
  }
  g[x][0] = ret;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int d = (dep[x] - dep[y]);
  for (int i = 0; i <= 18; i++)
    if (d & (1 << i)) x = fa[x][i];
  if (x == y) return x;
  for (int i = 18; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void insert(int old, int &rt, int l, int r, int x) {
  rt = ++trcnt;
  ls[rt] = ls[old], rs[rt] = rs[old];
  siz[rt] = siz[old];
  if (l == r) {
    siz[rt]++;
    return;
  }
  if (x <= ((l + r) / 2))
    insert(ls[old], ls[rt], l, ((l + r) / 2), x);
  else
    insert(rs[old], rs[rt], ((l + r) / 2) + 1, r, x);
  siz[rt] = siz[ls[rt]] + siz[rs[rt]];
}
int query(int old, int rt, int l, int r, int x, int y) {
  if (x <= l && r <= y) return siz[rt] - siz[old];
  int ret = 0;
  if (x <= ((l + r) / 2)) ret += query(ls[old], ls[rt], l, ((l + r) / 2), x, y);
  if (y >= ((l + r) / 2) + 1)
    ret += query(rs[old], rs[rt], ((l + r) / 2) + 1, r, x, y);
  return ret;
}
bool check(int x, int y) {
  if (L[x] > L[y]) swap(x, y);
  return query(root[L[x] - 1], root[R[x]], 1, n, L[y], R[y]) > 0;
}
int main() {
  scanf("%d", &n);
  for (i = 2; i <= n; i++) {
    scanf("%d", &o);
    add(o, i);
    add(i, o);
  }
  dfs1(1);
  for (i = 1; i <= n; i++) tag[i] = i;
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &o, &p);
    if (L[o] > L[p]) swap(o, p);
    int l = lca(o, p);
    if (dep[l] < dep[tag[o]]) tag[o] = l;
    if (dep[l] < dep[tag[p]]) tag[p] = l;
    a[i] = make_pair(L[o], L[p]);
  }
  dfs2(1);
  for (i = 1; i <= 18; i++)
    for (int x = 1; x <= n; x++) g[x][i] = g[g[x][i - 1]][i - 1];
  sort(a + 1, a + 1 + m);
  for (i = 1; i <= m; i++) {
    insert(rt[i - 1], rt[i], 1, n, a[i].second);
    root[a[i].first] = rt[i];
  }
  for (i = 1; i <= n; i++)
    if (root[i] == 0) root[i] = root[i - 1];
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &o, &p);
    int ans = 0;
    int l = lca(o, p);
    for (i = 18; i >= 0; i--)
      if (dep[g[o][i]] > dep[l]) ans += (1 << i), o = g[o][i];
    for (i = 18; i >= 0; i--)
      if (dep[g[p][i]] > dep[l]) ans += (1 << i), p = g[p][i];
    if (L[o] > L[p]) swap(o, p);
    if (R[o] >= R[p]) {
      if (dep[g[p][0]] <= dep[o])
        printf("%d\n", ans + 1);
      else
        printf("-1\n");
      continue;
    }
    if (g[o][0] == o || g[p][0] == p) {
      printf("-1\n");
      continue;
    }
    if (check(o, p))
      printf("%d\n", ans + 1);
    else
      printf("%d\n", ans + 2);
  }
}
