#include <bits/stdc++.h>
#pragma comment(linker, "/STACK:256000000")
using namespace std;
const int INF = (int)(1e9 + 1e5);
const long long LINF = (long long)(1e18);
const long long MX = 100500;
const double EPS = 1e-9;
const int MOD = 1000000007;
int tnum;
const int MAXN = 200500;
const int LOG = 25;
int n, m, k;
vector<vector<int>> g;
vector<vector<int>> pa;
vector<vector<int>> ro;
int tin[MAXN], tout[MAXN], timer;
int ans[MAXN];
pair<int, int> r[MAXN];
pair<int, int> qu[MAXN];
int p[MAXN][LOG];
int h[MAXN];
int mx[MAXN][LOG];
int lca_r[MAXN], lca_q[MAXN];
int tre[MAXN << 2];
pair<int, int> ch[MAXN];
int prev_sum[MAXN];
void init() {
  scanf("%d", &n);
  g.resize(n + 1);
  for (int i = 2; i <= n; ++i) {
    int q;
    scanf("%d", &q);
    g[q].push_back(i);
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", &r[i].first, &r[i].second);
  }
  scanf("%d", &k);
  for (int i = 1; i <= k; ++i) {
    scanf("%d%d", &qu[i].first, &qu[i].second);
  }
}
int get_sum(int tv, int tl, int tr, int l, int r) {
  if (l > r) {
    return 0;
  }
  if (tl == l && r == tr) {
    return tre[tv];
  }
  int tm = (tl + tr) >> 1;
  return get_sum(tv * 2, tl, tm, l, min(tm, r)) +
         get_sum(tv * 2 + 1, tm + 1, tr, max(l, tm + 1), r);
}
void add(int tv, int tl, int tr, int pos) {
  ++tre[tv];
  if (tl < tr) {
    int tm = (tl + tr) >> 1;
    if (pos <= tm) {
      add(tv * 2, tl, tm, pos);
    } else {
      add(tv * 2 + 1, tm + 1, tr, pos);
    }
  }
}
void dfs_init(int v, int par) {
  p[v][0] = par;
  h[v] = h[par] + 1;
  for (int i = 1; (1 << i) < h[v]; ++i) {
    p[v][i] = p[p[v][i - 1]][i - 1];
  }
  tin[v] = tout[v] = ++timer;
  mx[v][0] = v;
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    dfs_init(to, v);
    tout[v] = tout[to];
  }
}
void update_mx(int v, int cand) {
  if (h[cand] < h[mx[v][0]]) {
    mx[v][0] = cand;
  }
}
void dfs_calc_mx(int v) {
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    dfs_calc_mx(to);
    update_mx(v, mx[to][0]);
  }
}
void dfs_calc_routes(int v) {
  for (int i = 1; i < LOG; ++i) {
    mx[v][i] = mx[mx[v][i - 1]][i - 1];
  }
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    dfs_calc_routes(to);
  }
}
bool is_parent(int p, int v) { return tin[p] <= tin[v] && tout[v] <= tout[p]; }
int get_lca(int a, int b) {
  if (is_parent(a, b)) {
    return a;
  }
  for (int i = LOG - 1; i >= 0; --i) {
    if (p[a][i] && !is_parent(p[a][i], b)) {
      a = p[a][i];
    }
  }
  return p[a][0];
}
int get_cnt(int v, int p) {
  if (v == p) {
    return 0;
  }
  if (h[mx[v][LOG - 1]] > h[p]) {
    return -1;
  }
  int res = 0;
  for (int i = LOG - 1; i >= 0; --i) {
    int cur = mx[v][i];
    if (h[cur] > h[p]) {
      v = cur;
      res += (1 << i);
    }
  }
  return ++res;
}
int get_vertex(int v, int cnt) {
  if (cnt == -1) {
    return v;
  }
  for (int i = 0; i < LOG; ++i) {
    if (cnt & (1 << i)) {
      v = mx[v][i];
    }
  }
  return v;
}
void dfs_check(int v) {
  for (int i = 0; i < pa[v].size(); ++i) {
    int num = pa[v][i];
    prev_sum[num] = get_sum(1, 1, n, tin[ch[num].second], tout[ch[num].second]);
  }
  for (int i = 0; i < ro[v].size(); ++i) {
    add(1, 1, n, tin[ro[v][i]]);
  }
  for (int i = 0; i < g[v].size(); ++i) {
    int to = g[v][i];
    dfs_check(to);
  }
  for (int i = 0; i < pa[v].size(); ++i) {
    int num = pa[v][i];
    auto cur_sum = get_sum(1, 1, n, tin[ch[num].second], tout[ch[num].second]);
    if (cur_sum != prev_sum[num]) {
      --ans[num];
    }
  }
}
void solve() {
  dfs_init(1, 0);
  ro.resize(n + 1);
  for (int i = 1; i <= m; ++i) {
    if (tin[r[i].first] > tin[r[i].second]) {
      swap(r[i].first, r[i].second);
    }
    lca_r[i] = get_lca(r[i].first, r[i].second);
    update_mx(r[i].first, lca_r[i]);
    update_mx(r[i].second, lca_r[i]);
    ro[r[i].first].push_back(r[i].second);
  }
  dfs_calc_mx(1);
  dfs_calc_routes(1);
  pa.resize(n + 1);
  for (int i = 1; i <= k; ++i) {
    if (tin[qu[i].first] > tin[qu[i].second]) {
      swap(qu[i].first, qu[i].second);
    }
    lca_q[i] = get_lca(qu[i].first, qu[i].second);
    int cntl = get_cnt(qu[i].first, lca_q[i]);
    int cntr = get_cnt(qu[i].second, lca_q[i]);
    if (cntl == -1 || cntr == -1) {
      ans[i] = -1;
      continue;
    }
    ans[i] = cntl + cntr;
    if (qu[i].first != lca_q[i] && qu[i].second != lca_q[i]) {
      ch[i].first = get_vertex(qu[i].first, cntl - 1);
      ch[i].second = get_vertex(qu[i].second, cntr - 1);
      pa[ch[i].first].push_back(i);
    }
  }
  dfs_check(1);
}
void print_answer() {
  for (int i = 1; i <= k; ++i) {
    printf("%d\n", ans[i]);
  }
}
void precalc() {}
void run() {
  precalc();
  int t = 1;
  for (tnum = 1; tnum <= t; ++tnum) {
    init();
    solve();
    print_answer();
  }
}
int main() {
  srand(90);
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  run();
  return 0;
}
