Problem: In the NN country, there are n cities, numbered from 1 to n, and n - 1 roads, connecting them. There is a roads path between any two cities.

There are m bidirectional bus routes between cities. Buses drive between two cities taking the shortest path with stops in every city they drive through. Travelling by bus, you can travel from any stop on the route to any other. You can travel between cities only by bus.

You are interested in q questions: is it possible to get from one city to another and what is the minimum number of buses you need to use for it?

Input

The first line contains a single integer n (2 ≤ n ≤ 2 ⋅ 10^5) — the number of cities.

The second line contains n - 1 integers p_2, p_3, …, p_n (1 ≤ p_i < i), where p_i means that cities p_i and i are connected by road.

The third line contains a single integer m (1 ≤ m ≤ 2 ⋅ 10^5) — the number of bus routes.

Each of the next m lines contains 2 integers a and b (1 ≤ a, b ≤ n, a ≠ b), meaning that there is a bus route between cities a and b. It is possible that there is more than one route between two cities.

The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of questions you are interested in.

Each of the next q lines contains 2 integers v and u (1 ≤ v, u ≤ n, v ≠ u), meaning that you are interested if it is possible to get from city v to city u and what is the minimum number of buses you need to use for it.

Output

Print the answer for each question on a separate line. If there is no way to get from one city to another, print -1. Otherwise print the minimum number of buses you have to use.

Examples

Input

7
1 1 1 4 5 6
4
4 2
5 4
1 3
6 7
6
4 5
3 5
7 2
4 5
3 2
5 3


Output

1
3
-1
1
2
3


Input

7
1 1 2 3 4 1
4
4 7
3 5
7 6
7 6
6
4 6
3 1
3 2
2 7
6 3
5 3


Output

1
-1
-1
1
-1
1

Note

<image> Routes for first sample are marked on the picture. 

Solution (in CPP):

Solution:
#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;
}