#include <bits/stdc++.h>
using namespace std;
int n;
int par[200009], in[200009], ou[200009], spt[200009][22], dep[200009],
    up[200009];
pair<int, int> pr[200009];
int bup[200009][22];
int ans[200009];
vector<int> al[200009];
int tim;
vector<pair<pair<int, int>, int> > qu;
void dfs_p(int x, int p) {
  dep[x] = dep[p] + 1;
  for (int i = 0; i < (int)al[x].size(); i++) dfs_p(al[x][i], x);
}
void lca_init() {
  int root = 1;
  dep[root] = -1;
  dfs_p(root, root);
  for (int l = 0; l < 22; l++) {
    for (int i = 1; i <= n; i++) {
      if (l == 0) {
        spt[i][l] = par[i];
        continue;
      }
      spt[i][l] = spt[spt[i][l - 1]][l - 1];
    }
  }
}
int lca(int u, int v) {
  if (u == v) return u;
  if (dep[u] < dep[v]) return lca(v, u);
  for (int i = 22 - 1; i >= 0; i--) {
    if (dep[spt[u][i]] >= dep[v]) u = spt[u][i];
  }
  for (int i = 22 - 1; i >= 0; i--)
    if (spt[u][i] != spt[v][i]) {
      u = spt[u][i];
      v = spt[v][i];
    }
  return u == v ? u : spt[u][0];
}
void dfs(int v) {
  in[v] = tim++;
  int m = al[v].size();
  int p = v;
  for (int i = 0; i < m; i++) {
    int u = al[v][i];
    dfs(u);
    if (dep[bup[u][0]] < dep[p]) p = bup[u][0];
  }
  if (up[v] != 0 && dep[up[v]] < dep[p]) p = up[v];
  bup[v][0] = p;
  ou[v] = tim++;
}
int f1(int v, int l) {
  int i = 22 - 1;
  int ret = 0;
  while (i >= 0) {
    int u = bup[v][i];
    if (dep[u] > dep[l]) {
      ret += (1 << i);
      v = u;
    }
    i--;
  }
  if (v != l) {
    ret++;
    v = bup[v][0];
  }
  if (dep[v] > dep[l]) return -1;
  return ret;
}
int f2(int u, int r) {
  int i = 22 - 1;
  while (i >= 0) {
    if (1 << i <= r) {
      u = bup[u][i];
    }
    i--;
  }
  return u;
}
bool cmp(pair<pair<int, int>, int> a, pair<pair<int, int>, int> b) {
  return ou[a.first.second] < ou[b.first.second];
}
bool cmp2(pair<int, int> a, pair<int, int> b) {
  return in[a.second] < in[b.second];
}
struct node {
  int si, ei;
  int v, lz;
  node(int sii, int eii, int vv) {
    si = sii;
    ei = eii;
    v = vv;
  }
  node() { si = ei = v = 0; }
};
struct seg_tree {
  node nd[8 * 200009];
  void init(int in, int s, int e) {
    node &n = nd[in];
    if (s == e) {
      n = node(s, e, -1);
      return;
    }
    int mid = (s + e) / 2;
    init(2 * in, s, mid);
    init(2 * in + 1, mid + 1, e);
    n = merge(nd[2 * in], nd[2 * in + 1]);
  }
  node merge(node a, node b) { return node(a.si, b.ei, max(a.v, b.v)); }
  void upd_nd(node &n, int v) { n.v = max(n.v, v); }
  node query_r(int in, int s, int e) {
    node &n = nd[in];
    if (n.si == s && n.ei == e) return n;
    int mid = (n.si + n.ei) / 2;
    if (e <= mid)
      return query_r(2 * in, s, e);
    else if (s > mid)
      return query_r(2 * in + 1, s, e);
    else
      return merge(query_r(2 * in, s, mid), query_r(2 * in + 1, mid + 1, e));
  }
  void update_p(int in, int i, int v) {
    node &n = nd[in];
    if (n.si == n.ei) {
      upd_nd(n, v);
      return;
    }
    int mid = (n.si + n.ei) / 2;
    if (i <= mid)
      update_p(2 * in, i, v);
    else
      update_p(2 * in + 1, i, v);
    n = merge(nd[2 * in], nd[2 * in + 1]);
  }
};
seg_tree st;
int main() {
  cin >> n;
  par[1] = 1;
  for (int i = 2; i <= n; i++) {
    int a;
    scanf("%d", &a);
    al[a].push_back(i);
    par[i] = a;
  }
  lca_init();
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    int l = lca(u, v);
    if (up[u] == 0 || dep[up[u]] > dep[l]) {
      up[u] = l;
    }
    if (up[v] == 0 || dep[up[v]] > dep[l]) {
      up[v] = l;
    }
    pr[i] = make_pair(u, v);
  }
  tim = 0;
  dfs(1);
  for (int i = 0; i < m; i++) {
    if (in[pr[i].first] > in[pr[i].second]) swap(pr[i].first, pr[i].second);
  }
  for (int i = 1; i < 22; i++) {
    for (int j = 1; j <= n; j++) {
      bup[j][i] = bup[bup[j][i - 1]][i - 1];
    }
  }
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    int l = lca(u, v);
    if (dep[u] > dep[v]) swap(u, v);
    if (u == l) {
      ans[i] = f1(v, u);
      continue;
    }
    int u1 = f1(u, l);
    int v1 = f1(v, l);
    if (u1 == -1 || v1 == -1) {
      ans[i] = -1;
    } else {
      ans[i] = u1 + v1;
      u1 = f2(u, u1 - 1);
      v1 = f2(v, v1 - 1);
      if (in[u1] > in[v1]) swap(u1, v1);
      qu.push_back(make_pair(make_pair(u1, v1), i));
    }
  }
  sort(qu.begin(), qu.end(), cmp);
  sort(pr, pr + m, cmp2);
  int qs = qu.size();
  st.init(1, 0, tim);
  int ii = 0;
  for (int i = 0; i < qs; i++) {
    int u = qu[i].first.first, v = qu[i].first.second;
    int j = qu[i].second;
    while (ii < m && in[pr[ii].second] <= ou[v]) {
      st.update_p(1, in[pr[ii].first], in[pr[ii].second]);
      ii++;
    }
    int x = st.query_r(1, in[u], ou[u]).v;
    if (x >= in[v]) {
      ans[j]--;
    }
  }
  for (int i = 0; i < q; i++) cout << ans[i] << endl;
}
