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 int N = 201010;
const int B = 1 << 18;
const int LG = 18;
int cnt[N], hv[N], srt[N], ord[N], orde[N], up[N], rnk[N], anc[N][LG], clk,
    go[N][LG];
pair<int, int> tr[B << 1];
vector<int> adj[N];
vector<pair<int, int>> rs;
vector<int> tr2[B << 1];
void dfs0(int u) {
  cnt[u] = 1;
  hv[u] = -1;
  for (auto &x : adj[u]) {
    rnk[x] = rnk[u] + 1;
    dfs0(x);
    if (hv[u] == -1 || cnt[hv[u]] < cnt[x]) hv[u] = x;
    cnt[u] += cnt[x];
  }
}
void dfs1(int u, bool h = false) {
  ord[u] = clk++;
  srt[ord[u]] = u;
  if (h)
    up[u] = up[anc[u][0]];
  else
    up[u] = u;
  if (hv[u] >= 0) dfs1(hv[u], true);
  for (auto &x : adj[u]) {
    if (x == hv[u]) continue;
    dfs1(x);
  }
  orde[u] = clk;
}
int Go(int u, int d) {
  for (int i = LG; i--;)
    if (d & 1 << i) u = anc[u][i];
  return u;
}
int lca(int u, int v) {
  if (rnk[u] < rnk[v]) swap(u, v);
  u = Go(u, rnk[u] - rnk[v]);
  if (u == v) return u;
  for (int i = LG; i--;)
    if (anc[u][i] != anc[v][i]) u = anc[u][i], v = anc[v][i];
  return anc[u][0];
}
void add(int l, int r, pair<int, int> v) {
  for (l += B, r += B; l / 2 != r / 2; l /= 2, r /= 2) {
    if (!(l & 1)) tr[l + 1] = min(tr[l + 1], v);
    if (r & 1) tr[r - 1] = min(tr[r - 1], v);
  }
}
bool check(int l, int r, int s, int e) {
  for (l += B - 1, r += B; l / 2 != r / 2; l /= 2, r /= 2) {
    if (!(l & 1)) {
      auto it = lower_bound(tr2[l + 1].begin(), tr2[l + 1].end(), s);
      if (it != tr2[l + 1].end() && *it < e) return true;
    }
    if (r & 1) {
      auto it = lower_bound(tr2[r - 1].begin(), tr2[r - 1].end(), s);
      if (it != tr2[r - 1].end() && *it < e) return true;
    }
  }
  return false;
}
int main() {
  int n;
  scanf("%d", &n);
  anc[0][0] = -1;
  for (int i = 1; i < n; i++) {
    int x;
    scanf("%d", &x);
    x--;
    anc[i][0] = x;
    adj[x].push_back(i);
  }
  dfs0(0);
  dfs1(0);
  for (int i = 1; i < LG; i++)
    for (int j = 0; j < n; j++) {
      int a = anc[j][i - 1];
      if (a == -1)
        anc[j][i] = -1;
      else
        anc[j][i] = anc[a][i - 1];
    }
  for (int i = 1; i < B + B; i++) tr[i].first = 2012345678;
  int m;
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    rs.emplace_back(ord[u], ord[v]);
    int L = lca(u, v);
    pair<int, int> p = {rnk[L], L};
    while (up[u] != up[L]) {
      int uu = up[u];
      add(ord[uu] - 1, ord[u] + 1, p);
      u = anc[uu][0];
    }
    add(ord[L] - 1, ord[u] + 1, p);
    while (up[v] != up[L]) {
      int vv = up[v];
      add(ord[vv] - 1, ord[v] + 1, p);
      v = anc[vv][0];
    }
    add(ord[L] - 1, ord[v] + 1, p);
  }
  for (int i = 2; i < B + B; i++) {
    tr[i] = min(tr[i], tr[i >> 1]);
  }
  for (int i = 0; i < n; i++) {
    go[i][0] = tr[B + ord[i]].first == 2012345678 ? i : tr[B + ord[i]].second;
  }
  for (int j = 1; j < LG; j++)
    for (int i = 0; i < n; i++) {
      go[i][j] = go[go[i][j - 1]][j - 1];
    }
  sort(rs.begin(), rs.end());
  for (auto &x : rs) {
    tr2[B + x.first].push_back(x.second);
  }
  for (int i = B - 1; i; i--)
    merge(tr2[i << 1].begin(), tr2[i << 1].end(), tr2[i << 1 | 1].begin(),
          tr2[i << 1 | 1].end(), back_inserter(tr2[i]));
  int q;
  scanf("%d", &q);
  for (int tt = 0; tt < q; tt++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--;
    v--;
    int L = lca(u, v);
    if (L == u) swap(u, v);
    int x = u;
    for (int i = LG; i--;) x = go[x][i];
    if (rnk[x] > rnk[L]) {
      puts("-1");
      continue;
    }
    x = v;
    for (int i = LG; i--;) x = go[x][i];
    if (rnk[x] > rnk[L]) {
      puts("-1");
      continue;
    }
    int ans = 0;
    for (int i = LG; i--;) {
      if (rnk[go[u][i]] > rnk[L]) {
        ans += 1 << i;
        u = go[u][i];
      }
    }
    if (v == L) {
      printf("%d\n", ans + 1);
      continue;
    }
    for (int i = LG; i--;) {
      if (rnk[go[v][i]] > rnk[L]) {
        ans += 1 << i;
        v = go[v][i];
      }
    }
    if (check(ord[u], orde[u], ord[v], orde[v]) ||
        check(ord[v], orde[v], ord[u], orde[u])) {
      ans--;
    }
    printf("%d\n", ans + 2);
  }
}