#include <bits/stdc++.h>
using namespace std;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "Yes" : "No");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
vector<int> mp[200105];
int d[200105], p[200105][20], A[200105], B[200105];
int lwt[200105][20], Q, qu[200105], qv[200105], Ans[200105];
int lu[200105], lv[200105];
void initlca() {
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i <= n; i++) p[i][j] = p[p[i][j - 1]][j - 1];
}
int lca(int a, int b) {
  if (d[a] > d[b]) swap(a, b);
  int f = d[b] - d[a];
  for (int i = 0; (1 << i) <= f; i++)
    if ((1 << i) & f) b = p[b][i];
  if (a != b) {
    for (int i = 19; i >= 0; i--)
      if (p[a][i] != p[b][i]) {
        a = p[a][i];
        b = p[b][i];
      }
    a = p[a][0];
  }
  return a;
}
pair<int, int> dp[200105];
void dfs(int x) {
  for (int c : mp[x]) {
    dfs(c);
    mintt(dp[x], dp[c]);
  }
  if (dp[x].first <= d[x]) lwt[x][0] = dp[x].second;
}
pair<int, int> fdL(int x, int F) {
  int s = 0;
  for (int j = 19; ~j; j--) {
    if (lwt[x][j] == 0) continue;
    if (d[lwt[x][j]] <= d[F]) continue;
    s += 1 << j;
    x = lwt[x][j];
  }
  return {s, x};
}
vector<int> qs[200105], ways[200105];
int st[200105], ed[200105], cnt, stmp[200105];
int b[200105];
void update(int x, int v) {
  for (int i = x; i <= n; i += i & -i) {
    b[i] += v;
  }
}
int query(int x) {
  int ret = 0;
  for (; x > 0; ret += b[x], x -= x & -x)
    ;
  return ret;
}
int qy(int l, int r) { return query(r) - query(l - 1); }
void dfs2(int x) {
  st[x] = ++cnt;
  for (int c : mp[x]) dfs2(c);
  ed[x] = cnt;
}
void dfs3(int x) {
  for (int id : qs[x]) {
    stmp[id] = qy(st[lv[id]], ed[lv[id]]);
  }
  for (int ot : ways[x]) update(st[ot], 1);
  for (int c : mp[x]) dfs3(c);
  for (int id : qs[x]) {
    if (stmp[id] != qy(st[lv[id]], ed[lv[id]])) Ans[id]--;
  }
}
void fmain(int ID) {
  scanf("%d", &n);
  d[1] = 1;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p[i][0]);
    mp[p[i][0]].push_back(i);
    d[i] = d[p[i][0]] + 1;
  }
  initlca();
  scanf("%d", &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) dp[i] = {(1 << 30), (1 << 30)};
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    scanf("%d%d", A + i, B + i);
    int fa = lca(A[i], B[i]);
    mintt(dp[A[i]], {d[fa], fa});
    mintt(dp[B[i]], {d[fa], fa});
    ways[A[i]].push_back(B[i]);
    ways[B[i]].push_back(A[i]);
  }
  dfs(1);
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i <= n; i++)
      if (lwt[i][j - 1] && lwt[lwt[i][j - 1]][j - 1]) {
        int tar = lwt[lwt[i][j - 1]][j - 1];
        if (lwt[i][j] == 0 || d[tar] < d[lwt[i][j]]) lwt[i][j] = tar;
      }
  scanf("%d", &Q);
  for (int(i) = 1; (i) <= (int)(Q); (i)++) {
    scanf("%d%d", qu + i, qv + i);
    int fa = lca(qu[i], qv[i]);
    if (d[qv[i]] > d[qu[i]]) swap(qu[i], qv[i]);
    if (fa == qv[i]) {
      auto pp = fdL(qu[i], fa);
      if (lwt[pp.second][0] == 0 || d[lwt[pp.second][0]] > d[fa]) {
        Ans[i] = -1;
        continue;
      }
      assert(d[lwt[pp.second][0]] <= d[fa]);
      Ans[i] = pp.first + 1;
    } else {
      auto pp = fdL(qu[i], fa), ppv = fdL(qv[i], fa);
      if (lwt[pp.second][0] == 0 || d[lwt[pp.second][0]] > d[fa]) {
        Ans[i] = -1;
        continue;
      }
      if (lwt[ppv.second][0] == 0 || d[lwt[ppv.second][0]] > d[fa]) {
        Ans[i] = -1;
        continue;
      }
      lu[i] = pp.second;
      Ans[i] += pp.first + 1;
      lv[i] = ppv.second;
      Ans[i] += ppv.first + 1;
      qs[lu[i]].push_back(i);
    }
  }
  dfs2(1);
  dfs3(1);
  for (int(i) = 1; (i) <= (int)(Q); (i)++) printf("%d\n", Ans[i]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}
