#include <bits/stdc++.h>
using namespace std;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int n, m, q, i, j, f[200005][19], dep[200005], fa[200005][19], first[200005],
    ed[200005], ti, px[200005], py[200005], ans[200005], ss[200005];
vector<int> e[200005];
int gtmx(int x, int y) {
  if (!x) return y;
  if (!y) return x;
  return dep[x] < dep[y] ? x : y;
}
void dfs1(int x, int fa) {
  first[x] = ++ti;
  ::fa[x][0] = fa;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)
    if (*it != fa) {
      dep[*it] = dep[x] + 1;
      dfs1(*it, x);
    }
  ed[x] = ti;
}
void dfs2(int x, int fa) {
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)
    if (*it != fa) {
      dfs2(*it, x);
      f[x][0] = gtmx(f[x][0], f[*it][0]);
    }
  if (dep[f[x][0]] >= dep[x]) f[x][0] = 0;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int t = dep[x] - dep[y], i;
  for ((i) = (18); (i) >= (0); (i)--)
    if ((t >> i) & 1) x = fa[x][i];
  if (x == y) return x;
  for ((i) = (18); (i) >= (0); (i)--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
struct tt {
  int op, x, y, z;
};
vector<tt> v;
bool cmp(tt x, tt y) {
  if (x.x == y.x) return x.op < y.op;
  return x.x < y.x;
}
int s[200005];
void add(int x, int y) {
  while (x <= n) {
    s[x] += y;
    x += (x & -x);
  }
}
int qry(int x) {
  int ss = 0;
  while (x) {
    ss += s[x];
    x -= (x & -x);
  }
  return ss;
}
int main() {
  read(n);
  for ((i) = (2); (i) <= (n); (i)++) {
    int x;
    read(x);
    e[x].push_back(i);
  }
  dfs1(1, 0);
  for (((j)) = (1); ((j)) <= ((18)); ((j))++)
    for (((i)) = (1); ((i)) <= ((n)); ((i))++)
      fa[i][j] = fa[fa[i][j - 1]][j - 1];
  read(m);
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    int x, y;
    read(x);
    read(y);
    v.push_back((tt){0, first[x], first[y], 1});
    v.push_back((tt){0, first[y], first[x], 1});
    int z = lca(x, y);
    f[x][0] = gtmx(f[x][0], z);
    f[y][0] = gtmx(f[y][0], z);
  }
  dfs2(1, 0);
  for (((j)) = (1); ((j)) <= ((18)); ((j))++)
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) f[i][j] = f[f[i][j - 1]][j - 1];
  read(q);
  for (((i)) = (1); ((i)) <= ((q)); ((i))++) {
    int x, y, j;
    read(x);
    read(y);
    int z = lca(x, y);
    for ((j) = (18); (j) >= (0); (j)--)
      if (dep[f[x][j]] > dep[z]) {
        x = f[x][j];
        ans[i] += (1 << j);
      }
    for ((j) = (18); (j) >= (0); (j)--)
      if (dep[f[y][j]] > dep[z]) {
        y = f[y][j];
        ans[i] += (1 << j);
      }
    if (x != z && (!f[x][0] || dep[f[x][0]] > dep[z])) {
      ans[i] = -3;
      continue;
    }
    if (y != z && (!f[y][0] || dep[f[y][0]] > dep[z])) {
      ans[i] = -3;
      continue;
    }
    if (first[x] <= first[y] && ed[y] <= ed[x]) {
      ss[i] = 1;
      continue;
    }
    if (first[y] <= first[x] && ed[x] <= ed[y]) {
      ss[i] = 1;
      continue;
    }
    v.push_back((tt){i, ed[x], ed[y], 1});
    v.push_back((tt){i, ed[x], first[y] - 1, -1});
    v.push_back((tt){i, first[x] - 1, ed[y], -1});
    v.push_back((tt){i, first[x] - 1, first[y] - 1, 1});
  }
  sort(v.begin(), v.end(), cmp);
  for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++) {
    if (!v[i].op)
      add(v[i].y, v[i].z);
    else
      ss[v[i].op] += v[i].z * qry(v[i].y);
  }
  for (((i)) = (1); ((i)) <= ((q)); ((i))++) {
    printf("%d\n", ans[i] + 2 - !!ss[i]);
  }
  return 0;
}
