#include <bits/stdc++.h>
using namespace std;
int las[501000], nxt[501000], to[501000], n, f[501000 * 3][18], e[19],
    up[501000], dfn[501000], low[501000], g[501000 * 3][18], ans[501000],
    b[501000], tot, deep[501000], m, q, t[501000];
struct node {
  int x, y, y2, z;
} a[501000 * 2];
bool cnt(node a, node b) {
  return a.x < b.x || (a.x == b.x && a.z == 0 && b.z != 0);
}
void putin(int x, int y) {
  nxt[++tot] = las[x];
  las[x] = tot;
  to[tot] = y;
}
void dg(int x) {
  dfn[x] = ++tot;
  for (int i = las[x]; i; i = nxt[i]) {
    int y = to[i];
    deep[y] = deep[x] + 1;
    f[y][0] = x;
    dg(y);
  }
  low[x] = tot;
}
void dg1(int x) {
  for (int i = las[x]; i; i = nxt[i]) {
    int y = to[i];
    dg1(y);
    if (deep[up[y]] < deep[up[x]]) up[x] = up[y];
  }
  g[x][0] = up[x];
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  for (int i = 17; i >= 0; i--)
    if (deep[f[x][i]] >= deep[y]) x = f[x][i];
  for (int i = 17; i >= 0; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  if (x != y) x = f[x][0];
  return x;
}
int go_up(int &x, int y) {
  int ans = 0;
  for (int i = 17; i >= 0; i--)
    if (deep[g[x][i]] > deep[y]) x = g[x][i], ans += e[i];
  return ans;
}
void ptin(int x, int y) {
  tot++;
  a[tot].x = x;
  a[tot].y = y;
  a[tot].z = 0;
}
int lowbit(int x) { return x & (-x); }
void ins(int x) {
  for (; x <= n; x += lowbit(x)) t[x]++;
}
int get(int x) {
  int ans = 0;
  for (; x; x -= lowbit(x)) ans += t[x];
  return ans;
}
int main() {
  e[0] = 1;
  for (int i = 1; i <= 18; i++) e[i] = e[i - 1] * 2;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) up[i] = i;
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    putin(x, i);
  }
  tot = 0;
  deep[1] = 1;
  dg(1);
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];
  scanf("%d", &m);
  tot = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int z = lca(x, y);
    if (deep[z] < deep[up[x]]) up[x] = z;
    if (deep[z] < deep[up[y]]) up[y] = z;
    ptin(dfn[x], dfn[y]);
    ptin(dfn[y], dfn[x]);
  }
  dg1(1);
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++) g[i][j] = g[g[i][j - 1]][j - 1];
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int z = lca(x, y);
    ans[i] = go_up(x, z) + go_up(y, z);
    if (deep[up[x]] > deep[z] || deep[up[y]] > deep[z]) ans[i] = -1;
    if ((z == x || z == y) && ans[i] != -1)
      b[i] = -10000, ans[i]++;
    else {
      tot++;
      a[tot].x = dfn[x] - 1, a[tot].y = dfn[y], a[tot].y2 = low[y],
      a[tot].z = -i;
      tot++;
      a[tot].x = low[x], a[tot].y = dfn[y], a[tot].y2 = low[y], a[tot].z = i;
    }
    if (x == y) ans[i] = 0;
  }
  sort(a + 1, a + tot + 1, cnt);
  int j = 1;
  for (int i = 0; i <= n; i++) {
    for (; a[j].x == i; j++) {
      if (a[j].z == 0) ins(a[j].y);
      if (a[j].z < 0) b[-a[j].z] -= get(a[j].y2) - get(a[j].y - 1);
      if (a[j].z > 0) b[a[j].z] += get(a[j].y2) - get(a[j].y - 1);
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i] == -1)
      printf("-1\n");
    else if (b[i] < 0)
      printf("%d\n", ans[i]);
    else
      printf("%d\n", ans[i] + (b[i] > 0 ? 1 : 2));
  }
}
