#include <bits/stdc++.h>
using namespace std;
int read() {
  char ch;
  for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar())
    ;
  int x = ch - '0';
  for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar())
    x = x * 10 + ch - '0';
  return x;
}
void write(int x) {
  if (!x) {
    puts("0");
    return;
  }
  if (x < 0) putchar('-'), x = -x;
  char ch[20];
  int tot = 0;
  for (; x; x /= 10) ch[++tot] = x % 10 + '0';
  for (int i = tot; i >= 1; i--) putchar(ch[i]);
  puts("");
}
const int N = 4e5 + 5;
int t[N], nxt[N], lst[N], l;
void add(int x, int y) {
  t[++l] = y;
  nxt[l] = lst[x];
  lst[x] = l;
}
vector<int> vec[N];
vector<pair<int, int> > que[N];
int n, m, q, tot, fa[N][18], up[N][18], dep[N], dfn[N], sz[N], tmp[N], an[N];
void dfs(int x) {
  dep[x] = dep[fa[x][0]] + 1;
  dfn[x] = ++tot;
  sz[x] = 1;
  for (int j = 1; j <= 17; j++) fa[x][j] = fa[fa[x][j - 1]][j - 1];
  for (int i = lst[x]; i; i = nxt[i]) dfs(t[i]), sz[x] += sz[t[i]];
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int j = 17; j >= 0; j--)
    if (dep[fa[x][j]] > dep[y]) x = fa[x][j];
  x = dep[x] == dep[y] ? x : fa[x][0];
  for (int j = 17; j >= 0; j--)
    if (fa[x][j] != fa[y][j]) x = fa[x][j], y = fa[y][j];
  return x == y ? x : fa[x][0];
}
void prepare() {
  for (int i = n; i >= 1; i--) {
    up[i][0] = i;
    for (int j = lst[i]; j; j = nxt[j])
      up[i][0] = dep[up[t[j]][0]] < dep[up[i][0]] ? up[t[j]][0] : up[i][0];
    for (int j = 0; j < vec[i].size(); j++) {
      int x = lca(vec[i][j], i);
      up[i][0] = dep[x] < dep[up[i][0]] ? x : up[i][0];
    }
  }
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++) up[i][j] = up[up[i][j - 1]][j - 1];
}
int tr[N];
void I(int x) {
  for (; x <= n; x += x & -x) tr[x]++;
}
int Q(int x) {
  int res = 0;
  for (; x; x -= x & -x) res += tr[x];
  return res;
}
void solve(int x) {
  for (int i = 0; i < que[x].size(); i++) {
    int y = que[x][i].first, id = que[x][i].second;
    tmp[id] = Q(dfn[y] + sz[y] - 1) - Q(dfn[y] - 1);
  }
  for (int i = 0; i < vec[x].size(); i++) I(dfn[vec[x][i]]);
  for (int i = lst[x]; i; i = nxt[i]) solve(t[i]);
  for (int i = 0; i < que[x].size(); i++) {
    int y = que[x][i].first, id = que[x][i].second;
    an[id] += (Q(dfn[y] + sz[y] - 1) - Q(dfn[y] - 1)) == tmp[id];
  }
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) {
    fa[i][0] = read();
    add(fa[i][0], i);
  }
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  dfs(1);
  prepare();
  q = read();
  for (int i = 1; i <= q; i++) {
    int x = read(), y = read(), z = lca(x, y);
    an[i] = 1;
    for (int j = 17; j >= 0; j--) {
      if (dep[up[x][j]] > dep[z]) x = up[x][j], an[i] += 1 << j;
      if (dep[up[y][j]] > dep[z]) y = up[y][j], an[i] += 1 << j;
    }
    if (dep[up[x][0]] > dep[z] || dep[up[y][0]] > dep[z]) {
      an[i] = -1;
      continue;
    }
    if (x != z && y != z) que[x].push_back(make_pair(y, i));
  }
  solve(1);
  for (int i = 1; i <= q; i++) write(an[i]);
  return 0;
}
