#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = f ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) return putchar('-'), write(-x);
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
const int N = 2e5 + 5, MAXN = 1e7 + 5;
struct edge {
  int next, to;
} e[N << 1];
int n, m, Q, fa[N], head[N], dep[N], dfn[N], id[N], tot, cou, rev[N], rfn[N],
    siz[N], f[N][21], g[N][21], rt[N], cnt, tree[MAXN], ls[MAXN], rs[MAXN];
vector<int> num[N];
void add(int u, int v) {
  e[++cnt] = {head[u], v};
  head[u] = cnt;
}
void dfs(int x) {
  dep[x] = dep[f[x][0]] + 1, dfn[x] = ++tot, rev[tot] = x, siz[x] = 1;
  for (int i = 1; i <= 20; i++) f[x][i] = f[f[x][i - 1]][i - 1];
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    dfs(y), siz[x] += siz[y];
  }
  rfn[x] = tot;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; ~i; i--)
    if (dep[f[x][i]] >= dep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 20; ~i; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
void DFS1(int x) {
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    DFS1(y);
    if (g[y][0] == x) continue;
    if (dep[g[y][0]] < dep[x] && g[y][0])
      if (!g[x][0] || dep[g[x][0]] > dep[g[y][0]]) g[x][0] = g[y][0];
  }
}
void DFS2(int x) {
  for (int i = 1; i <= 20; i++) g[x][i] = g[g[x][i - 1]][i - 1];
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    DFS2(y);
  }
}
void Add(int l, int r, int pre, int &k, int x) {
  if (!k) k = ++tot;
  if (l == r) return tree[k] = tree[pre] + 1, void();
  tree[k] = tree[pre] + 1;
  if (x <= ((l + r) >> 1))
    rs[k] = rs[pre], Add(l, ((l + r) >> 1), ls[pre], ls[k], x);
  else
    ls[k] = ls[pre], Add(((l + r) >> 1) + 1, r, rs[pre], rs[k], x);
}
int Query(int l, int r, int k1, int k2, int x, int y) {
  if (l >= x && r <= y) return tree[k2] - tree[k1];
  if (x > ((l + r) >> 1))
    return Query(((l + r) >> 1) + 1, r, rs[k1], rs[k2], x, y);
  if (y <= ((l + r) >> 1))
    return Query(l, ((l + r) >> 1), ls[k1], ls[k2], x, y);
  return Query(l, ((l + r) >> 1), ls[k1], ls[k2], x, y) +
         Query(((l + r) >> 1) + 1, r, rs[k1], rs[k2], x, y);
}
int main() {
  read(n);
  for (int i = 2; i <= n; i++) read(f[i][0]), add(f[i][0], i);
  dfs(1);
  read(m);
  for (int i = 1, u, v; i <= m; i++) {
    read(u), read(v);
    int lca = LCA(u, v);
    if ((!g[u][0] || dep[g[u][0]] > dep[lca]) && u != lca) g[u][0] = lca;
    if ((!g[v][0] || dep[g[v][0]] > dep[lca]) && v != lca) g[v][0] = lca;
    if (dfn[u] > dfn[v]) swap(u, v);
    num[dfn[v]].push_back(dfn[u]);
  }
  DFS1(1), DFS2(1);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < num[i].size(); j++)
      ++cou, Add(1, n, rt[cou - 1], rt[cou], num[i][j]);
    id[i] = cou;
  }
  read(Q);
  while (Q--) {
    int u, v, res = 0;
    read(u), read(v);
    if (dep[u] > dep[v]) swap(u, v);
    int lca = LCA(u, v);
    if (lca == u) {
      for (int i = 20; ~i; i--)
        if (dep[g[v][i]] > dep[u]) v = g[v][i], res += (1 << i);
      if (!g[v][0])
        puts("-1");
      else
        write(res + 1), puts("");
    } else {
      for (int i = 20; ~i; i--)
        if (dep[g[u][i]] > dep[lca]) u = g[u][i], res += (1 << i);
      for (int i = 20; ~i; i--)
        if (dep[g[v][i]] > dep[lca]) v = g[v][i], res += (1 << i);
      res += 2;
      if (!g[v][0] || !g[u][0]) {
        puts("-1");
        continue;
      }
      if (dfn[u] < dfn[v]) swap(u, v);
      if (Query(1, n, rt[id[dfn[u] - 1]], rt[id[rfn[u]]], dfn[v], rfn[v]))
        res--;
      write(res), puts("");
    }
  }
}
