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 MN = 200005, P2 = (1 << 19), MTS = 2 * P2 + 5, inf = 1000000005,
          mod = 1000000007;
const int LG = 20;
const long long INF = 1000000000000000005LL;
pair<int, int> min_dep[LG][MN];
int hop[LG][MN];
int pre[MN], post[MN], dep[MN];
vector<int> from[MN], G[MN];
vector<pair<int, int> > zap[MN];
int bus_a[MN], bus_b[MN], bus_lca[MN], ans[MN];
int suma_przed[MN], used[MN];
int T[MTS];
int licznik, n, m;
void add(int v, int x) {
  x += P2;
  while (x) {
    T[x] += v;
    x >>= 1;
  }
}
int sum(int a, int b) {
  a += P2, b += P2;
  int ret = 0;
  while (a < b) {
    if (a & 1) ret += T[a++];
    if (!(b & 1)) ret += T[b--];
    a >>= 1, b >>= 1;
  }
  if (a == b) ret += T[a];
  return ret;
}
void dfs_prep(int x, int d) {
  dep[x] = d;
  pre[x] = ++licznik;
  for (auto v : G[x])
    if (!pre[v]) {
      hop[0][v] = x;
      dfs_prep(v, d + 1);
    }
  post[x] = ++licznik;
}
void dfs_md(int x) {
  min_dep[0][x] = {dep[x], x};
  for (auto b : from[x])
    min_dep[0][x] = min(min_dep[0][x], {dep[bus_lca[b]], bus_lca[b]});
  for (auto v : G[x])
    if (!min_dep[0][v].first) {
      dfs_md(v);
      min_dep[0][x] = min(min_dep[0][x], min_dep[0][v]);
    }
}
void dfs_opt(int x) {
  used[x] = 1;
  for (auto z : zap[x]) suma_przed[z.second] = sum(pre[z.first], post[z.first]);
  for (auto b : from[x]) {
    int to = (x == bus_a[b] ? bus_b[b] : bus_a[b]);
    add(1, pre[to]);
  }
  for (auto v : G[x])
    if (!used[v]) dfs_opt(v);
  for (auto z : zap[x])
    if (suma_przed[z.second] != sum(pre[z.first], post[z.first]))
      --ans[z.second];
}
bool child(int a, int b) { return (pre[a] >= pre[b] && post[a] <= post[b]); }
int lca(int a, int b) {
  if (child(a, b)) return b;
  if (child(b, a)) return a;
  int s = LG - 1;
  while (s >= 0) {
    if (child(b, hop[s][a]))
      --s;
    else
      a = hop[s][a];
  }
  a = hop[0][a];
  return a;
}
pair<int, int> buses_up(int x, int y) {
  int s = LG - 1, ret = 0;
  while (s >= 0) {
    if (min_dep[s][x].first > dep[y]) {
      ret += (1 << s);
      if (ret > m) return {inf, inf};
      x = min_dep[s][x].second;
    } else {
      --s;
    }
  }
  if (dep[x] > dep[y]) ++ret;
  if (ret > m) return {inf, inf};
  return {ret, x};
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    G[p].push_back(i);
    G[i].push_back(p);
  }
  dfs_prep(1, 1);
  hop[0][1] = 1;
  for (int i = 1; i < LG; ++i)
    for (int j = 1; j <= n; ++j) hop[i][j] = hop[i - 1][hop[i - 1][j]];
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    int a, b, l;
    scanf("%d%d", &a, &b);
    l = lca(a, b);
    bus_a[i] = a;
    bus_b[i] = b;
    bus_lca[i] = l;
    from[a].push_back(i);
    from[b].push_back(i);
  }
  dfs_md(1);
  for (int i = 1; i < LG; ++i)
    for (int j = 1; j <= n; ++j)
      min_dep[i][j] = min_dep[i - 1][min_dep[i - 1][j].second];
  int q;
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (child(u, v)) {
      ans[i] = buses_up(u, v).first;
    } else if (child(v, u)) {
      ans[i] = buses_up(v, u).first;
    } else {
      int l = lca(u, v);
      pair<int, int> le = buses_up(u, l), pr = buses_up(v, l);
      if (max(le.first, pr.first) == inf) {
        ans[i] = inf;
        continue;
      }
      ans[i] = le.first + pr.first;
      zap[le.second].push_back({pr.second, i});
    }
  }
  dfs_opt(1);
  for (int i = 1; i <= q; ++i)
    if (ans[i] > 1e8)
      printf("-1\n");
    else
      printf("%d\n", ans[i]);
}