#include <bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 10;
const int MAX_LOG = 20;
vector<int> e[MAXN];
vector<int> fen[MAXN];
vector<int> vertex[MAXN];
vector<pair<int, pair<int, int> > > d[MAXN];
int f[MAXN][MAX_LOG];
int par[MAXN][MAX_LOG];
int x[MAXN];
int y[MAXN];
int b[MAXN];
int st[MAXN];
int ft[MAXN];
int ans[MAXN];
int t = 0;
bool is_par(int v, int u) { return (st[v] <= st[u] && ft[v] >= ft[u]); }
int lca(int v, int u) {
  for (int i = MAX_LOG - 1; i >= 0; i--) {
    if (!is_par(par[v][i], u)) {
      v = par[v][i];
    }
  }
  return (is_par(v, u) ? v : par[v][0]);
}
pair<int, int> mbtlca(int v, int u) {
  int res = 0;
  for (int i = MAX_LOG - 1; i >= 0; i--) {
    if (!is_par(f[v][i], u)) {
      v = f[v][i];
      res += (1 << i);
    }
  }
  return make_pair(v, res);
}
void update(int id, int p) {
  for (; p < fen[id].size(); p += ((p) & -(p))) {
    fen[id][p]++;
  }
}
int get_sum(int id, int p) {
  int sum = 0;
  for (; p > 0; p -= ((p) & -(p))) {
    sum += fen[id][p];
  }
  return sum;
}
void set_dfs(int v) {
  st[v] = ++t;
  for (int i = 0; i < vertex[v].size(); i++) {
    par[vertex[v][i]][0] = v;
    set_dfs(vertex[v][i]);
  }
  ft[v] = t;
}
void f_dfs(int v) {
  for (int i = 0; i < vertex[v].size(); i++) {
    f_dfs(vertex[v][i]);
    if (st[f[vertex[v][i]][0]] < st[f[v][0]]) {
      f[v][0] = f[vertex[v][i]][0];
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    vertex[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    f[i][0] = i;
  }
  set_dfs(1);
  par[1][0] = 1;
  for (int i = 1; i < MAX_LOG; i++) {
    for (int j = 1; j <= n; j++) {
      par[j][i] = par[par[j][i - 1]][i - 1];
    }
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int v, u;
    cin >> v >> u;
    if (st[v] > st[u]) {
      swap(v, u);
    }
    int w = lca(v, u);
    e[w].push_back(st[v]);
    d[w].push_back(make_pair(st[u], make_pair(0, st[v])));
    if (st[w] < st[f[v][0]]) {
      f[v][0] = w;
    }
    if (st[w] < st[f[u][0]]) {
      f[u][0] = w;
    }
  }
  f_dfs(1);
  for (int i = 1; i < MAX_LOG; i++) {
    for (int j = 1; j <= n; j++) {
      f[j][i] = f[f[j][i - 1]][i - 1];
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> x[i] >> y[i];
    if (st[x[i]] > st[y[i]]) {
      swap(x[i], y[i]);
    }
    if (is_par(x[i], y[i])) {
      pair<int, int> z = mbtlca(y[i], x[i]);
      if (is_par(f[z.first][0], x[i])) {
        ans[i] = z.second + 1;
      } else {
        ans[i] = -1;
      }
    } else {
      pair<int, int> zy = mbtlca(y[i], x[i]), zx = mbtlca(x[i], y[i]);
      if (is_par(f[zy.first][0], x[i]) && is_par(f[zx.first][0], y[i])) {
        ans[i] = zy.second + zx.second + 2;
        x[i] = zx.first;
        y[i] = zy.first;
        int w = lca(x[i], y[i]);
        d[w].push_back(make_pair(ft[y[i]], make_pair(i, 1)));
        d[w].push_back(make_pair(st[y[i]] - 1, make_pair(i, -1)));
      } else {
        ans[i] = -1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(e[i].begin(), e[i].end());
    e[i].resize(unique(e[i].begin(), e[i].end()) - e[i].begin());
    fen[i].resize((int)(e[i].size()) + 10);
    for (int j = 0; j < (int)(e[i].size()) + 10; j++) {
      fen[i].push_back(0);
    }
    sort(d[i].begin(), d[i].end());
    for (int j = 0; j < d[i].size(); j++) {
      if (d[i][j].second.first == 0) {
        int p = lower_bound(e[i].begin(), e[i].end(), d[i][j].second.second) -
                e[i].begin() + 1;
        update(i, p);
      } else {
        int l = lower_bound(e[i].begin(), e[i].end(),
                            st[x[d[i][j].second.first]]) -
                e[i].begin(),
            r = upper_bound(e[i].begin(), e[i].end(),
                            ft[x[d[i][j].second.first]]) -
                e[i].begin();
        b[d[i][j].second.first] +=
            d[i][j].second.second * (get_sum(i, r) - get_sum(i, l));
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] - (b[i] > 0) << endl;
  }
}
