#include <bits/stdc++.h>
using namespace std;
inline void File() {}
template <typename T>
inline void read(T &_) {
  _ = 0;
  T __ = getchar(), ___ = 1;
  while (!isdigit(__)) {
    if (__ == '-') ___ = -1;
    __ = getchar();
  }
  while (isdigit(__)) {
    _ = (_ << 1) + (_ << 3) + (__ ^ '0');
    __ = getchar();
  }
  _ *= ___;
}
template <typename T>
inline bool Chkmax(T &_, T __) {
  return _ < __ ? _ = __, 1 : 0;
}
template <typename T>
inline bool Chkmin(T &_, T __) {
  return _ > __ ? _ = __, 1 : 0;
}
const int N = 2e5 + 1e2;
int e, n, m, q, stp, clk, dfs_clk;
int Log[N << 1], St[N << 1][20], Go[N][20], pos[N], dep[N], siz[N];
int beg[N], nex[N << 1], to[N << 1], dfn[N], ans[N];
struct Bus {
  int v, lca;
};
vector<Bus> a[N];
struct Fenwick_Tree {
  int sum[N];
  inline int lowbit(int x) { return x & -x; }
  inline void Add(int x, int val) {
    for (int i = x; i <= n + 10; i += lowbit(i)) sum[i] += val;
  }
  inline int Sum(int x) {
    int res = 0;
    for (int i = x; i; i -= lowbit(i)) res += sum[i];
    return res;
  }
  inline int query(int l, int r) { return Sum(r) - Sum(l - 1); }
} T;
struct ASK {
  int v, id, Ans;
};
vector<ASK> Ans[N];
inline void add(int x, int y) { to[++e] = y, nex[e] = beg[x], beg[x] = e; }
inline int MIN(int x, int y) { return dep[x] < dep[y] ? x : y; }
inline void Dfs1(int x, int ff) {
  dfn[x] = ++dfs_clk;
  siz[x] = 1;
  St[pos[x] = ++clk][0] = x;
  dep[x] = dep[ff] + 1;
  for (int i = beg[x]; i; i = nex[i]) {
    if (to[i] != ff) {
      Dfs1(to[i], x);
      St[++clk][0] = x;
      siz[x] += siz[to[i]];
    }
  }
}
inline void Init() {
  Dfs1(1, 0);
  for (int i = 2; i <= clk; i++) Log[i] = Log[i >> 1] + 1;
  for (int i = 1; (1 << i) <= clk; i++)
    for (int j = 1; j + (1 << i) - 1 <= clk; j++)
      St[j][i] = MIN(St[j][i - 1], St[j + (1 << (i - 1))][i - 1]);
}
inline int LCA(int x, int y) {
  int l = pos[x], r = pos[y];
  if (r < l) swap(l, r);
  int k = Log[r - l + 1];
  return MIN(St[l][k], St[r - (1 << k) + 1][k]);
}
inline int MAX(int x, int y) {
  if (x == 0) return y;
  if (y == 0) return x;
  return dep[x] > dep[y] ? y : x;
}
inline void Dfs2(int x, int ff) {
  for (auto BUS : a[x]) Go[x][0] = MAX(Go[x][0], BUS.lca);
  for (int i = beg[x]; i; i = nex[i]) {
    if (to[i] != ff) {
      Dfs2(to[i], x);
      Go[x][0] = MAX(Go[x][0], Go[to[i]][0]);
    }
  }
  if (Go[x][0] == x) Go[x][0] = 0;
}
inline int Jump(int u, int lca) {
  stp = 0;
  bool flag = 0;
  for (int i = 18; i >= 0; i--) {
    if (dep[Go[u][i]] > dep[lca]) u = Go[u][i], stp += i, flag = 1;
  }
  if (flag) stp = (1 << stp);
  return u;
}
inline void Dfs3(int x, int ff) {
  vector<int> pre;
  for (auto y : Ans[x]) {
    pre.push_back(T.query(dfn[y.v], dfn[y.v] + siz[y.v] - 1));
  }
  for (auto y : a[x]) T.Add(dfn[y.v], 1);
  for (int i = beg[x]; i; i = nex[i]) {
    if (to[i] != ff) {
      Dfs3(to[i], x);
    }
  }
  for (int i = 0, Ed = Ans[x].size(); i < Ed; i++) {
    if (T.query(dfn[Ans[x][i].v], dfn[Ans[x][i].v] + siz[Ans[x][i].v] - 1) !=
        pre[i])
      ans[Ans[x][i].id] = Ans[x][i].Ans + 1;
    else
      ans[Ans[x][i].id] = Ans[x][i].Ans + 2;
  }
}
int main() {
  File();
  read(n);
  for (int p, i = 2; i <= n; i++) read(p), add(p, i), add(i, p);
  Init();
  read(m);
  for (int i = 1, u, v; i <= m; i++) {
    read(u), read(v);
    a[u].push_back((Bus){v, LCA(u, v)});
    a[v].push_back((Bus){u, LCA(v, u)});
  }
  Dfs2(1, 0);
  for (int i = 1; (1 << i) <= n; i++)
    for (int j = 1; j <= n; j++) Go[j][i] = Go[Go[j][i - 1]][i - 1];
  read(q);
  for (int i = 1, u, v; i <= q; i++) {
    read(u), read(v);
    int lu = Jump(u, LCA(u, v)), A = stp;
    int lv = Jump(v, LCA(u, v)), B = stp;
    if (lu == LCA(u, v)) {
      if (Go[lv][0] && dep[Go[lv][0]] <= dep[lu])
        ans[i] = A + B + 1;
      else
        ans[i] = -1;
      continue;
    } else if (lv == LCA(u, v)) {
      if (Go[lu][0] && dep[Go[lu][0]] <= dep[lv])
        ans[i] = A + B + 1;
      else
        ans[i] = -1;
      continue;
    }
    if (!Go[lu][0]) {
      ans[i] = -1;
      continue;
    }
    if (!Go[lv][0]) {
      ans[i] = -1;
      continue;
    }
    Ans[lu].push_back((ASK){lv, i, A + B});
  }
  Dfs3(1, 0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}
