#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline void chkmax(T &x, const T2 &y) {
  if (x < y) x = y;
}
template <class T, class T2>
inline void chkmin(T &x, const T2 &y) {
  if (x > y) x = y;
}
const int MAXN = (int)3e5 + 42 + 17;
const int MAXLOG = 20;
int n, m, q;
vector<int> G[MAXN];
vector<int> li[MAXN];
pair<int, int> e[MAXN];
int answer[MAXN];
template <class T>
struct fenwick {
  int sz;
  T tr[MAXN];
  void init(int n) {
    sz = n + 1;
    memset(tr, 0, sizeof(tr));
  }
  T query(int idx) {
    T ans = 0;
    for (; idx >= 1; idx -= (idx & -idx)) ans += tr[idx];
    return ans;
  }
  void update(int idx, T val) {
    if (idx <= 0) return;
    for (; idx <= sz; idx += (idx & -idx)) tr[idx] += val;
  }
  T query(int l, int r) { return query(r) - query(l - 1); }
};
int qu[MAXN], qv[MAXN];
bool add1[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int pr;
    cin >> pr;
    G[pr].push_back(i + 2);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> e[i].first >> e[i].second;
    li[e[i].first].push_back(e[i].second);
    li[e[i].second].push_back(e[i].first);
  }
  cin >> q;
  for (int i = 0; i < q; i++) cin >> qu[i] >> qv[i];
}
int st[MAXN], en[MAXN], dfs_time = 0;
int par[MAXN][MAXLOG];
int dep[MAXN];
vector<int> que[MAXN];
vector<int> to_rem[MAXN];
fenwick<int> t;
void dfs_lca(int u, int d = 0) {
  dep[u] = d;
  st[u] = ++dfs_time;
  for (int i = 1; i < MAXLOG; i++) par[u][i] = par[par[u][i - 1]][i - 1];
  for (int v : G[u])
    if (v != par[u][0]) {
      par[v][0] = u;
      dfs_lca(v, d + 1);
    }
  en[u] = dfs_time;
}
inline bool upper(int u, int v) { return st[u] <= st[v] && en[v] <= en[u]; }
int lca(int u, int v) {
  if (upper(u, v)) return u;
  if (upper(v, u)) return v;
  int a = u;
  for (int i = MAXLOG - 1; i >= 0; i--)
    if (!upper(par[a][i], v)) a = par[a][i];
  return par[a][0];
}
int parent(int u, int up) {
  int a = u;
  for (int i = MAXLOG - 1; i >= 0; i--)
    if (up & (1 << i)) a = par[a][i];
  return a;
}
void lca_precompute(int root) {
  for (int i = 0; i < MAXLOG; i++) par[root][i] = root;
  dfs_time = 0;
  dfs_lca(root);
}
int tr_sz[MAXN];
void pre_dfs(int u, int pr) {
  tr_sz[u] = li[u].size() + 1 + to_rem[u].size();
  for (int v : G[u])
    if (v != pr) {
      pre_dfs(v, u);
      tr_sz[u] += tr_sz[v];
    }
}
void add_vertex(int u) {
  for (auto it : li[u]) t.update(st[it], 1);
}
void clear(int u, int pr) {
  for (auto it : li[u]) t.update(st[it], -1);
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], 1);
    t.update(st[vv], 1);
  }
  for (int v : G[u])
    if (v != pr) clear(v, u);
}
void add(int u, int pr) {
  add_vertex(u);
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], -1);
    t.update(st[vv], -1);
  }
  for (int v : G[u])
    if (v != pr) add(v, u);
}
void dfs(int u, int pr, int keep) {
  pair<int, int> mx = {-1, -1};
  for (int v : G[u])
    if (v != pr) mx = max(mx, {tr_sz[v], v});
  for (int v : G[u])
    if (v != pr && v != mx.second) dfs(v, u, 0);
  if (mx.second != -1) dfs(mx.second, u, 1);
  for (int v : G[u])
    if (v != pr && v != mx.second) add(v, u);
  add_vertex(u);
  for (int i : que[u])
    if (t.query(st[qv[i]], en[qv[i]])) add1[i] = 1;
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], -1);
    t.update(st[vv], -1);
  }
  if (keep) return;
  clear(u, pr);
}
int up[MAXN][20];
void get_up(int u, int pr) {
  up[u][0] = u;
  for (int x : li[u]) {
    int ax = lca(x, u);
    if (up[u][0] == -1 || dep[ax] < dep[up[u][0]]) up[u][0] = ax;
  }
  for (int v : G[u])
    if (v != pr) {
      get_up(v, u);
      if (up[u][0] == -1 || dep[up[v][0]] < dep[up[u][0]]) up[u][0] = up[v][0];
    }
}
int go_up(int u, int l, int idx) {
  for (int o = 19; o >= 0; o--)
    if (up[u][o] != -1 && !upper(up[u][o], l)) {
      u = up[u][o];
      answer[idx] += (1 << o);
    }
  return u;
}
void solve() {
  lca_precompute(1);
  get_up(1, 1);
  for (int i = 1; i < 20; i++)
    for (int x = 1; x <= n; x++) up[x][i] = up[up[x][i - 1]][i - 1];
  for (int i = 0; i < q; i++) {
    int anc = lca(qu[i], qv[i]);
    qu[i] = go_up(qu[i], anc, i);
    qv[i] = go_up(qv[i], anc, i);
    if (qu[i] != anc && (up[qu[i]][0] == -1 || dep[up[qu[i]][0]] > dep[anc])) {
      answer[i] = -1;
      continue;
    }
    if (qv[i] != anc && (up[qv[i]][0] == -1 || dep[up[qv[i]][0]] > dep[anc])) {
      answer[i] = -1;
      continue;
    }
    if (qu[i] == anc || qv[i] == anc) add1[i] = 1;
    que[qu[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    int u = e[i].first, v = e[i].second;
    to_rem[lca(u, v)].push_back(i);
  }
  t.init(n + 2);
  pre_dfs(1, 1);
  dfs(1, 1, 0);
  for (int i = 0; i < q; i++) {
    if (answer[i] != -1) {
      if (!add1[i])
        answer[i] += 2;
      else
        answer[i] += 1;
    }
    cout << answer[i] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}
