#include <bits/stdc++.h>
using namespace std;
const int MAX = 212345;
vector<int> edge[MAX];
vector<int> end_path[MAX];
vector<pair<int, int> > query_pair[MAX];
vector<int> store;
int ans[MAX];
int dep[MAX], f[MAX][20], lb[MAX], rb[MAX], tot;
int jump[MAX][20], go[MAX];
int n;
long long tree[MAX * 4];
void add(int y) {
  while (y < MAX * 4) {
    tree[y] += 1;
    y += y & (-y);
  }
}
long long query(int y) {
  long long sum = 0;
  while (y) {
    sum += tree[y];
    y -= y & (-y);
  }
  return sum;
}
long long get(int l, int r) { return query(r) - query(l - 1); }
void dfs_lca(int u, int fa, int depth) {
  lb[u] = ++tot;
  dep[u] = depth + 1;
  f[u][0] = fa;
  for (auto v : edge[u]) {
    if (v == fa) continue;
    dfs_lca(v, u, depth + 1);
  }
  rb[u] = tot;
}
void init_LCA() {
  dfs_lca(1, 0, 0);
  for (int i = 1; i < 20; i++) {
    for (int j = 1; j <= n; j++) {
      f[j][i] = f[f[j][i - 1]][i - 1];
    }
  }
}
int LCA(int u, int v) {
  if (dep[v] > dep[u]) swap(u, v);
  int diff = dep[u] - dep[v];
  for (int i = 19; i >= 0; i--) {
    if (diff >> i & 1) u = f[u][i];
  }
  if (u == v) return u;
  for (int i = 19; i >= 0; i--) {
    if (f[u][i] != f[v][i]) {
      u = f[u][i];
      v = f[v][i];
    }
  }
  return f[u][0];
}
void dfs_jump(int u, int fa) {
  store.push_back(u);
  for (auto v : edge[u]) {
    if (v == fa) continue;
    dfs_jump(v, u);
    go[u] = max(go[u], go[v] - 1);
  }
  jump[u][0] = *(store.end() - go[u] - 1);
  store.pop_back();
}
void init_jump() {
  dfs_jump(1, 0);
  for (int i = 1; i < 20; i++) {
    for (int j = 1; j <= n; j++) {
      jump[j][i] = jump[jump[j][i - 1]][i - 1];
    }
  }
}
int eu, ev;
int JUMP(int u, int v, int x) {
  if (jump[u][19] != jump[v][19]) return -1e9;
  int rst = 0;
  for (int i = 19; i >= 0; i--) {
    if (dep[jump[u][i]] > x) {
      rst += (1 << i);
      u = jump[u][i];
    }
    if (dep[jump[v][i]] > x) {
      rst += (1 << i);
      v = jump[v][i];
    }
  }
  eu = u;
  ev = v;
  return rst;
}
void solve(int u, int fa) {
  vector<long long> store;
  for (auto v : query_pair[u]) store.push_back(get(lb[v.second], rb[v.second]));
  for (auto v : end_path[u]) add(lb[v]);
  for (auto v : edge[u]) {
    if (v == fa) continue;
    solve(v, u);
  }
  for (int i = 0; i < query_pair[u].size(); i++) {
    int v = query_pair[u][i].second;
    int id = query_pair[u][i].first;
    if (store[i] != get(lb[v], rb[v])) ans[id]--;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    edge[i].push_back(x);
    edge[x].push_back(i);
  }
  init_LCA();
  int m;
  scanf("%d", &m);
  while (m--) {
    int u, v;
    scanf("%d %d", &u, &v);
    end_path[u].push_back(v);
    end_path[v].push_back(u);
    int t = LCA(u, v);
    go[u] = max(go[u], dep[u] - dep[t]);
    go[v] = max(go[v], dep[v] - dep[t]);
  }
  init_jump();
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (lb[u] > lb[v]) swap(u, v);
    int t = LCA(u, v);
    if (t == u || t == v) {
      if (u == v)
        ans[i] = 0;
      else
        ans[i] = JUMP(u, v, dep[t]) + 1;
    } else {
      ans[i] = JUMP(u, v, dep[t]) + 2;
      query_pair[eu].emplace_back(i, ev);
    }
  }
  solve(1, 0);
  for (int i = 1; i <= q; i++) {
    printf("%d\n", max(-1, ans[i]));
  }
}
