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 = 200005, inf = 1e9;
int lvl[N], par[18][N], Up[18][N], start[N], finish[N];
int Ans[N], mark[N], traversal_time, n, m, q;
vector<int> child[N], events[N], delet[N];
vector<pair<int, int> > Queries[N];
multiset<int> st[N];
int lca(int a, int b) {
  if (lvl[a] < lvl[b]) swap(a, b);
  for (int i = 17; i >= 0; --i)
    if (lvl[par[i][a]] >= lvl[b]) a = par[i][a];
  for (int i = 17; i >= 0; --i)
    if (par[i][a] != par[i][b]) a = par[i][a], b = par[i][b];
  return (a == b) ? a : par[0][a];
}
void dfs(int u) {
  start[u] = ++traversal_time;
  for (int v : child[u]) lvl[v] = lvl[u] + 1, dfs(v);
  finish[u] = traversal_time;
}
void prep_paths(int u) {
  Up[0][u] = min(Up[0][u], lvl[u]);
  for (int v : child[u]) {
    prep_paths(v);
    Up[0][u] = min(Up[0][u], Up[0][v]);
  }
}
void solve(int u) {
  for (int v : child[u]) {
    solve(v);
    if (st[v].size() > st[u].size()) st[u].swap(st[v]);
    for (auto cur : st[v]) st[u].insert(cur);
  }
  for (int v : events[u]) st[u].insert(v);
  for (auto v : Queries[u]) {
    auto it = st[u].lower_bound(start[v.first]);
    if ((it != st[u].end()) && (*it <= finish[v.first])) mark[v.second] = 1;
  }
  for (int v : delet[u]) st[u].erase(st[u].find(v));
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    scanf("%d", &par[0][i]);
    child[par[0][i]].push_back(i);
  }
  for (int j = 1; j < 18; ++j)
    for (int i = 1; i <= n; ++i) par[j][i] = par[j - 1][par[j - 1][i]];
  lvl[1] = 1, dfs(1);
  scanf("%d", &m);
  memset(Up, 127, sizeof Up);
  for (int i = 1; i <= m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    int k = lca(a, b);
    Up[0][a] = min(Up[0][a], lvl[k]);
    Up[0][b] = min(Up[0][b], lvl[k]);
    events[a].push_back(start[b]);
    events[b].push_back(start[a]);
    delet[k].push_back(start[b]);
    delet[k].push_back(start[a]);
  }
  prep_paths(1);
  for (int i = 1; i <= n; ++i) {
    int diff = lvl[i] - Up[0][i];
    Up[0][i] = i;
    for (int j = 17; j >= 0; --j)
      if (diff & (1 << j)) Up[0][i] = par[j][Up[0][i]];
  }
  for (int j = 1; j < 18; ++j)
    for (int i = 1; i <= n; ++i) Up[j][i] = Up[j - 1][Up[j - 1][i]];
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    int k = lca(a, b);
    if (k == b) swap(a, b);
    if (k == a) {
      for (int j = 17; j >= 0; --j)
        if (lvl[Up[j][b]] > lvl[a]) b = Up[j][b], Ans[i] += (1 << j);
      Ans[i]++;
      continue;
    }
    mark[i] = 2;
    for (int j = 17; j >= 0; --j)
      if (lvl[Up[j][a]] > lvl[k]) a = Up[j][a], Ans[i] += (1 << j);
    for (int j = 17; j >= 0; --j)
      if (lvl[Up[j][b]] > lvl[k]) b = Up[j][b], Ans[i] += (1 << j);
    if (lvl[Up[0][b]] > lvl[k]) Ans[i] = inf;
    if (lvl[Up[0][a]] > lvl[k]) Ans[i] = inf;
    Queries[a].push_back(make_pair(b, i));
    Queries[b].push_back(make_pair(a, i));
  }
  solve(1);
  for (int i = 1; i <= q; ++i)
    printf("%d\n", (Ans[i] < N) ? (Ans[i] + mark[i]) : -1);
}