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;
const long long INF = 1e9 + 10, MAX = 2e5 + 10, MOD = 1e9 + 7, MAXL = 20;
void OUT(long double o, int x) {
  cout << fixed << setprecision(x) << o;
  return;
}
int dp[MAXL][MAX], h[MAX], st[MAX], en[MAX], now = 0, ans[MAX];
pair<int, int> go[MAXL][MAX];
vector<int> adj[MAX];
set<int> sack[MAX];
vector<pair<pair<int, int>, int> > qu[MAX];
void dfs(int v) {
  h[v] = h[dp[0][v]] + 1;
  go[0][v] = {h[v], v};
  st[v] = ++now;
  for (int i = 1; i <= 18; i++) dp[i][v] = dp[i - 1][dp[i - 1][v]];
  for (int u : adj[v]) dfs(u);
  en[v] = now;
}
void dfs1(int v) {
  for (int u : adj[v]) {
    dfs1(u);
    go[0][v] = min(go[0][v], go[0][u]);
  }
}
void dfs2(int v) {
  for (int i = 1; i <= 18; i++) go[i][v] = go[i - 1][go[i - 1][v].second];
  for (int u : adj[v]) dfs2(u);
}
void dfs3(int v) {
  pair<int, int> x = {1, v};
  for (int u : adj[v]) {
    dfs3(u);
    x = max({sack[u].size(), u}, x);
  }
  sack[v].swap(sack[x.second]);
  for (int u : adj[v]) {
    for (int k : sack[u]) sack[v].insert(k);
  }
  for (pair<pair<int, int>, int> u : qu[v]) {
    int y = *sack[v].lower_bound(u.first.first);
    if (y <= u.first.second) ans[u.second]--;
  }
}
int gp(int v, int x) {
  for (int i = 0; i <= 18; i++)
    if (x & (1 << i)) v = dp[i][v];
  return v;
}
int lca(int v, int u) {
  if (h[v] > h[u]) swap(v, u);
  u = gp(u, h[u] - h[v]);
  if (v == u) return v;
  for (int i = 18; i >= 0; i--)
    if (dp[i][v] != dp[i][u]) v = dp[i][v], u = dp[i][u];
  return dp[0][v];
}
pair<int, int> dis(int v, int p) {
  int x = 0;
  for (int i = 18; i >= 0; i--) {
    if (go[i][v].first > h[p]) {
      x += (1 << i);
      v = go[i][v].second;
    }
  }
  return {x + 1, v};
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n, m, q;
  cin >> n;
  for (int i = 1; i <= n; i++) sack[i].insert(INF);
  dp[0][1] = 1;
  for (int i = 2; i <= n; i++) {
    cin >> dp[0][i];
    adj[dp[0][i]].push_back(i);
  }
  dfs(1);
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int v, u;
    cin >> v >> u;
    if (h[v] > h[u]) swap(v, u);
    int z = lca(v, u);
    go[0][u] = min(go[0][u], {h[z], z});
    if (!(st[v] < st[u] && st[u] <= en[v])) {
      go[0][v] = min(go[0][v], {h[z], z});
      sack[v].insert(st[u]);
      sack[u].insert(st[v]);
    }
  }
  dfs1(1);
  dfs2(1);
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int v, u;
    cin >> v >> u;
    if (h[v] > h[u]) swap(v, u);
    if (!(st[v] < st[u] && st[u] <= en[v])) {
      int z = lca(v, u);
      if (go[18][u].first > h[z] || go[18][v].first > h[z])
        ans[i] = -1;
      else {
        pair<int, int> x = dis(u, z), y = dis(v, z);
        ans[i] = x.first + y.first;
        qu[x.second].push_back({{st[y.second], en[y.second]}, i});
      }
    } else {
      if (go[18][u].first > h[v])
        ans[i] = -1;
      else
        ans[i] = dis(u, v).first;
    }
  }
  dfs3(1);
  for (int i = 1; i <= q; i++) cout << ans[i] << "\n";
  return 0;
}