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;
template <class T, class U>
void ckmin(T &a, U b) {
  if (a > b) a = b;
}
template <class T, class U>
void ckmax(T &a, U b) {
  if (a < b) a = b;
}
int N, M, T, Q;
int parent[200013], depth[200013];
vector<int> edge[200013];
int ancestor[20][200013];
int jump[20][200013];
int go[200013];
int st[200013], ft[200013];
vector<int> guys[200013];
int ans[200013], stor[200013];
vector<pair<int, int> > ad[200013], sb[200013];
int fen[200013];
void update(int idx, int v) {
  for (int e = idx + 1; e <= N; e += e & (-e)) fen[e] += v;
}
int query(int idx) {
  int res = 0;
  for (int e = idx + 1; e > 0; e -= e & (-e)) res += fen[e];
  return res;
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (auto i = (20) - 1; i >= (0); i--) {
    if ((depth[v] - depth[u]) >= (1 << i)) v = ancestor[i][v];
  }
  if (u == v) return u;
  for (auto i = (20) - 1; i >= (0); i--) {
    if (ancestor[i][u] != ancestor[i][v]) {
      u = ancestor[i][u];
      v = ancestor[i][v];
    }
  }
  return parent[u];
}
void dfs(int u) {
  st[u] = T;
  ft[u] = T;
  T++;
  for (int v : edge[u]) {
    dfs(v);
    ft[u] = ft[v];
  }
}
int32_t main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed << setprecision(12);
  cerr << fixed << setprecision(4);
  cin >> N;
  parent[0] = N;
  for (auto i = (1); i < (N); i++) {
    cin >> parent[i];
    parent[i]--;
    depth[i] = depth[parent[i]] + 1;
    edge[parent[i]].push_back(i);
  }
  dfs(0);
  for (auto i = (0); i < (20); i++) {
    ancestor[i][N] = N;
  }
  for (auto i = (0); i < (N); i++) {
    ancestor[0][i] = parent[i];
  }
  for (auto i = (1); i < (20); i++) {
    for (auto j = (0); j < (N); j++) {
      ancestor[i][j] = ancestor[i - 1][ancestor[i - 1][j]];
    }
  }
  for (auto i = (0); i < (20); i++) {
    for (auto j = (0); j < (N); j++) {
      jump[i][j] = j;
    }
  }
  cin >> M;
  for (auto i = (0); i < (M); i++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u > v) swap(u, v);
    guys[st[u]].push_back(st[v]);
    guys[st[v]].push_back(st[u]);
    int w = lca(u, v);
    for (auto j = (20) - 1; j >= (0); j--) {
      if ((depth[u] - depth[w]) >= (1 << j)) {
        ckmin(jump[j][u], w);
        u = ancestor[j][u];
      }
      if ((depth[v] - depth[w]) >= (1 << j)) {
        ckmin(jump[j][v], w);
        v = ancestor[j][v];
      }
    }
  }
  for (auto i = (20) - 1; i >= (1); i--) {
    for (auto j = (0); j < (N); j++) {
      ckmin(jump[i - 1][j], jump[i][j]);
      ckmin(jump[i - 1][ancestor[i - 1][j]], jump[i][j]);
    }
  }
  for (auto i = (0); i < (N); i++) {
    go[i] = jump[0][i];
  }
  for (auto i = (1); i < (20); i++) {
    for (auto j = (0); j < (N); j++) {
      jump[i][j] = jump[i - 1][jump[i - 1][j]];
    }
  }
  cin >> Q;
  for (auto q = (0); q < (Q); q++) {
    int u, v;
    cin >> u >> v;
    u--;
    v--;
    if (u > v) swap(u, v);
    int w = lca(u, v);
    ans[q] = 2;
    for (auto i = (20) - 1; i >= (0); i--) {
      if (depth[jump[i][u]] > depth[w]) {
        ans[q] += (1 << i);
        u = jump[i][u];
      }
      if (depth[jump[i][v]] > depth[w]) {
        ans[q] += (1 << i);
        v = jump[i][v];
      }
    }
    if (depth[go[u]] > depth[w] || depth[go[v]] > depth[w]) {
      ans[q] = -1;
      continue;
    }
    if (u == w) {
      ans[q]--;
      continue;
    }
    sb[st[u]].push_back({v, q});
    ad[ft[u]].push_back({v, q});
  }
  for (auto i = (0); i < (N); i++) {
    for (pair<int, int> p : sb[i]) {
      int qid = p.second, u = p.first;
      stor[qid] -= (query(ft[u]) - query(st[u] - 1));
    }
    for (int x : guys[i]) {
      update(x, 1);
    }
    for (pair<int, int> p : ad[i]) {
      int qid = p.second, u = p.first;
      stor[qid] += (query(ft[u]) - query(st[u] - 1));
    }
  }
  for (auto i = (0); i < (Q); i++) {
    if (ans[i] != -1) ans[i] -= (stor[i] ? 1 : 0);
    cout << ans[i] << '\n';
  }
}