#include <bits/stdc++.h>
using namespace std;
template <class T>
inline void read(T &x) {
  x = 0;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int N = 2e5 + 10;
int d[N][19], p[N][19], dep[N], dfn[N], sz[N], n, m, id;
vector<int> G[N], U[N];
void dfs1(int u, int last) {
  dfn[u] = ++id, sz[u] = 1;
  p[u][0] = last, dep[u] = dep[last] + 1;
  for (int j = 1; j <= 18; ++j) p[u][j] = p[p[u][j - 1]][j - 1];
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v == last) continue;
    dfs1(v, u);
    sz[u] += sz[v];
  }
}
void dfs2(int u, int last) {
  d[u][0] = u;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v == last) continue;
    dfs2(v, u);
    if (dep[d[v][0]] < dep[d[u][0]]) d[u][0] = d[v][0];
  }
  for (int j = 0; j < U[u].size(); ++j)
    if (dep[d[u][0]] > dep[U[u][j]]) d[u][0] = U[u][j];
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int j = 18; j >= 0; --j)
    if (dep[x] - (1 << j) >= dep[y]) x = p[x][j];
  if (x == y) return x;
  for (int j = 18; j >= 0; --j)
    if (p[x][j] != p[y][j]) x = p[x][j], y = p[y][j];
  return p[x][0];
}
int Up(int &x, int f) {
  if (x == f) return -1;
  int ans = 0;
  for (int j = 18; j >= 0; --j)
    if (dep[d[x][j]] > dep[f]) x = d[x][j], ans += (1 << j);
  return ans;
}
int Ans[N], ex[N];
struct Que {
  int x, y;
} Q[N];
struct itm {
  int id, l, r, t;
};
vector<itm> ss[N];
vector<int> UPD[N];
struct BIT {
  int c[N];
  void add(int i, int t) {
    for (; i <= n; i += i & -i) c[i] += t;
  }
  int query(int i) {
    int ans = 0;
    for (; i; i -= i & -i) ans += c[i];
    return ans;
  }
} BT;
void work() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < UPD[i].size(); ++j) BT.add(UPD[i][j], 1);
    for (int j = 0; j < ss[i].size(); ++j)
      ex[ss[i][j].id] +=
          ss[i][j].t * (BT.query(ss[i][j].r) - BT.query(ss[i][j].l - 1));
  }
}
int main() {
  int x, y, q;
  read(n);
  for (int i = 2; i <= n; ++i) read(x), G[x].push_back(i);
  dfs1(1, 0);
  read(m);
  for (int i = 1; i <= m; ++i) {
    read(Q[i].x), read(Q[i].y);
    int L = LCA(Q[i].x, Q[i].y);
    U[Q[i].x].push_back(L), U[Q[i].y].push_back(L);
    if (dfn[Q[i].x] < dfn[Q[i].y])
      UPD[dfn[Q[i].x]].push_back(dfn[Q[i].y]);
    else
      UPD[dfn[Q[i].y]].push_back(dfn[Q[i].x]);
  }
  dfs2(1, 0);
  for (int j = 1; j <= 18; ++j)
    for (int i = 1; i <= n; ++i) d[i][j] = d[d[i][j - 1]][j - 1];
  read(q);
  for (int cur = 1; cur <= q; ++cur) {
    read(x), read(y);
    if (x == y) {
      Ans[cur] = 0;
      continue;
    }
    if (dep[x] < dep[y]) swap(x, y);
    int L = LCA(x, y);
    if (L == y) {
      if (dep[d[x][18]] > dep[y])
        Ans[cur] = -1;
      else
        Ans[cur] = Up(x, y) + 1;
      continue;
    }
    if (dep[d[x][18]] > dep[L] || dep[d[y][18]] > dep[L]) {
      Ans[cur] = -1;
      continue;
    }
    int fx = x, fy = y;
    Ans[cur] = Up(fx, L) + Up(fy, L) + 2;
    if (dfn[fx] > dfn[fy]) swap(fx, fy);
    ss[dfn[fx] - 1].push_back((itm){cur, dfn[fy], dfn[fy] + sz[fy] - 1, -1});
    ss[dfn[fx] + sz[fx] - 1].push_back(
        (itm){cur, dfn[fy], dfn[fy] + sz[fy] - 1, 1});
  }
  work();
  for (int i = 1; i <= q; ++i) {
    if (Ans[i] != -1 && ex[i]) Ans[i]--;
    printf("%d\n", Ans[i]);
  }
  return 0;
}
