#include <bits/stdc++.h>
using namespace std;
struct fenwickTree {
  vector<int> bit;
  int n;
  void init(int n) {
    this->n = n;
    bit.assign(n, 0);
  }
  int sum(int r) {
    int ret = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) ret += bit[r];
    return ret;
  }
  void add(int idx, int d) {
    for (; idx < n; idx = idx | (idx + 1)) bit[idx] += d;
  }
  int sum(int l, int r) { return sum(r) - sum(l - 1); }
  void init(vector<int> a) {
    init(a.size());
    for (size_t i = 0; i < a.size(); ++i) add(i, a[i]);
  }
};
const int Max = 2e5 + 3, Log = 20;
vector<int> adj[Max], route[Max];
vector<pair<int, int> > pairs[Max];
int memo[Max][Log], depth[Max], answer[Max], timeIn[Max], timeOut[Max];
int nthBus[Max][Log];
int highest[Max];
fenwickTree ft;
int LCA(int x, int y) {
  if (depth[x] < depth[y]) swap(x, y);
  int diff = depth[x] - depth[y];
  for (int k = Log - 1; k >= 0; --k) {
    if (diff & (1 << k)) {
      x = memo[x][k];
    }
  }
  for (int k = Log - 1; k >= 0; --k) {
    if (memo[x][k] != memo[y][k]) {
      x = memo[x][k];
      y = memo[y][k];
    }
  }
  if (x != y) x = memo[x][0];
  return x;
}
void dfs(int node, int prev, int Depth, int &preOrder) {
  timeIn[node] = ++preOrder;
  depth[node] = Depth;
  memo[node][0] = prev;
  for (int i = 1; i < Log; ++i) {
    memo[node][i] = memo[memo[node][i - 1]][i - 1];
  }
  for (int to : adj[node]) {
    if (to == prev) continue;
    dfs(to, node, Depth + 1, preOrder);
  }
  timeOut[node] = preOrder;
}
void dfs2(int node, int prev) {
  for (int to : adj[node]) {
    if (to == prev) continue;
    dfs2(to, node);
    if (depth[highest[to]] < depth[highest[node]]) {
      highest[node] = highest[to];
    }
  }
}
void dfs3(int node, int prev) {
  nthBus[node][0] = highest[node];
  for (int i = 1; i < Log; ++i) {
    nthBus[node][i] = nthBus[nthBus[node][i - 1]][i - 1];
  }
  for (int to : adj[node]) {
    if (to == prev) continue;
    dfs3(to, node);
  }
}
void dfs4(int node, int prev) {
  vector<int> prevSums(pairs[node].size());
  for (int i = 0; i < pairs[node].size(); ++i) {
    int other = pairs[node][i].first;
    prevSums[i] = ft.sum(timeIn[other], timeOut[other]);
  }
  for (int other : route[node]) {
    ft.add(timeIn[other], 1);
  }
  for (int to : adj[node]) {
    if (to == prev) continue;
    dfs4(to, node);
  }
  for (int i = 0; i < pairs[node].size(); ++i) {
    int other = pairs[node][i].first;
    int sum = ft.sum(timeIn[other], timeOut[other]);
    if (sum > prevSums[i]) {
      answer[pairs[node][i].second]--;
    }
  }
}
int leastBuses(int node, int goal) {
  if (node == goal) return 0;
  if (depth[goal] < depth[nthBus[node][Log - 1]]) return -1;
  int least = (3 << Log);
  int numBusses = 0;
  for (int k = Log - 1; k >= 0; --k) {
    if (depth[goal] >= depth[nthBus[node][k]]) {
      least = min(least, numBusses + (1 << k));
    } else {
      node = nthBus[node][k];
      numBusses += (1 << k);
    }
  }
  return least;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  int parent;
  for (int i = 2; i <= n; ++i) {
    cin >> parent;
    adj[i].push_back(parent);
    adj[parent].push_back(i);
  }
  int preOrder = 0;
  dfs(1, 1, 0, preOrder);
  for (int i = 1; i <= n; ++i) highest[i] = i;
  int q;
  cin >> q;
  int u, v;
  while (q--) {
    cin >> u >> v;
    if (timeIn[u] > timeIn[v]) swap(u, v);
    route[u].push_back(v);
    int lca = LCA(u, v);
    if (depth[lca] < depth[highest[u]]) {
      highest[u] = lca;
    }
    if (depth[lca] < depth[highest[v]]) {
      highest[v] = lca;
    }
  }
  dfs2(1, 1);
  dfs3(1, 1);
  cin >> q;
  for (int i = 0; i < q; ++i) {
    cin >> u >> v;
    if (u == v) {
      answer[i] = 0;
      continue;
    }
    int lca = LCA(u, v);
    int leastU = leastBuses(u, lca);
    int leastV = leastBuses(v, lca);
    if (leastU == -1 || leastV == -1) {
      answer[i] = -1;
      continue;
    }
    answer[i] = leastU + leastV;
    if (lca == u || lca == v) continue;
    leastU--, leastV--;
    if (leastU < 0 || leastV < 0) continue;
    for (int k = 0; k < Log; ++k) {
      if (leastU & (1 << k)) {
        u = nthBus[u][k];
      }
    }
    for (int k = 0; k < Log; ++k) {
      if (leastV & (1 << k)) {
        v = nthBus[v][k];
      }
    }
    if (u == v) continue;
    if (timeIn[u] > timeIn[v]) swap(u, v);
    pairs[u].push_back({v, i});
  }
  ft.init(n + n);
  dfs4(1, 1);
  for (int i = 0; i < q; ++i) cout << answer[i] << '\n';
  return 0;
}
