#include <bits/stdc++.h>
using namespace std;
const int Maxn = 200005;
int n, m, Q, sign, tot;
int h[Maxn], dep[Maxn], p[Maxn][20], L[Maxn], R[Maxn], upper[Maxn][20];
int fa[Maxn], ans[Maxn], cnt[Maxn], tr[Maxn];
void add(int x, int val) {
  for (int i = x; i <= n; i += i & -i) tr[i] += val;
}
int ask(int x) {
  int ret = 0;
  for (int i = x; i; i -= i & -i) ret += tr[i];
  return ret;
}
struct edge {
  int to, next;
} e[Maxn * 2];
struct node {
  int x, y, lca, id;
} b[Maxn], q[Maxn];
struct info {
  int x, l, r, f, id;
  bool operator<(const info& b) const {
    return x < b.x || (x == b.x && f < b.f);
  }
} w[Maxn * 6];
void addedge(int x, int y) {
  static int cnt;
  e[++cnt] = (edge){y, h[x]};
  h[x] = cnt;
}
void dfs(int x, int fa) {
  dep[x] = dep[fa] + 1;
  p[x][0] = fa;
  L[x] = ++sign;
  for (int i = 1; i <= 17; i++) p[x][i] = p[p[x][i - 1]][i - 1];
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (y == fa) continue;
    dfs(y, x);
  }
  R[x] = sign;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 17; ~i; i--)
    if (dep[p[x][i]] >= dep[y]) x = p[x][i];
  if (x == y) return x;
  for (int i = 17; ~i; i--)
    if (p[x][i] != p[y][i]) x = p[x][i], y = p[y][i];
  return p[x][0];
}
void dfs2(int x, int fa) {
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (y == fa) continue;
    dfs2(y, x);
    if (dep[upper[y][0]] < dep[upper[x][0]]) upper[x][0] = upper[y][0];
  }
}
void dfs3(int x, int fa) {
  for (int i = 1; i <= 17; i++) upper[x][i] = upper[upper[x][i - 1]][i - 1];
  for (int i = h[x]; i; i = e[i].next) {
    int y = e[i].to;
    if (y == fa) continue;
    dfs3(y, x);
  }
}
pair<int, int> ask(int x, int y) {
  int ans = 0;
  for (int i = 17; ~i; i--)
    if (dep[upper[x][i]] > dep[y]) x = upper[x][i], ans |= 1 << i;
  return make_pair(x, ans);
}
int find(int x) { return fa[x] == x ? x : fa[x] = find(fa[x]); }
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    addedge(x, i);
    addedge(i, x);
  }
  for (int i = 1; i <= n; i++) fa[i] = i;
  dfs(1, 0);
  for (int i = 1; i <= n; i++) upper[i][0] = i;
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y, lca;
    scanf("%d%d", &x, &y);
    if (L[x] > L[y]) swap(x, y);
    lca = ::lca(x, y);
    if (dep[upper[x][0]] > dep[lca]) upper[x][0] = lca;
    if (dep[upper[y][0]] > dep[lca]) upper[y][0] = lca;
    b[i] = (node){x, y, lca};
    w[++tot] = (info){L[x], L[y], 0, 1, 0};
    w[++tot] = (info){L[y], L[x], 0, 1, 0};
    x = find(x);
    y = find(y);
    while (x != y) {
      if (dep[x] < dep[y]) swap(x, y);
      x = fa[x] = find(p[x][0]);
    }
  }
  dfs2(1, 0);
  dfs3(1, 0);
  scanf("%d", &Q);
  for (int i = 1; i <= Q; i++) {
    int x, y, lca, px, py;
    pair<int, int> ret;
    scanf("%d%d", &x, &y);
    if (L[x] > L[y]) swap(x, y);
    lca = ::lca(x, y);
    q[i] = (node){x, y, lca, i};
    ret = ask(x, lca);
    ans[i] += ret.second;
    px = ret.first;
    ret = ask(y, lca);
    ans[i] += ret.second;
    py = ret.first;
    if (x != lca && y != lca) {
      w[++tot] = (info){L[px], L[py], R[py], 0, i};
      w[++tot] = (info){R[px], L[py], R[py], 2, i};
    } else
      ans[i]++;
  }
  sort(w + 1, w + tot + 1);
  for (int i = 1; i <= tot; i++) {
    if (w[i].f == 0) cnt[w[i].id] -= ask(w[i].r) - ask(w[i].l - 1);
    if (w[i].f == 1) add(w[i].l, 1);
    if (w[i].f == 2) {
      cnt[w[i].id] += ask(w[i].r) - ask(w[i].l - 1);
      if (cnt[w[i].id])
        ans[w[i].id]++;
      else
        ans[w[i].id] += 2;
    }
  }
  for (int i = 1; i <= Q; i++) {
    if (find(q[i].x) == find(q[i].y))
      cout << ans[i] << "\n";
    else
      puts("-1");
  }
}
