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 = 2e5 + 20;
int dep[N], fa[N][19], g[N][19], L[N], R[N], dfn;
vector<int> G[N], path[N];
vector<pair<int, int> > qq[N];
int ans[N], bo[N], lag[N], f[N];
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 17; i >= 0; i--)
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = 17; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
inline int cmax(int x, int y) { return dep[x] < dep[y] ? x : y; }
void dfs(int u) {
  L[u] = ++dfn;
  for (int v : G[u])
    if (v != fa[u][0]) {
      dfs(v);
      lag[u] = cmax(lag[u], lag[v]);
    }
  g[u][0] = lag[u];
  R[u] = dfn;
}
int n, m;
int query(int x) {
  int ret = 0;
  for (; x; x -= x & (-x)) ret += f[x];
  return ret;
}
void add(int x, int p) {
  for (; x <= n; x += x & (-x)) f[x] += p;
}
void dfs1(int u) {
  for (auto x : qq[u]) {
    int y = x.first;
    bo[x.second] = query(R[y]) - query(L[y] - 1);
  }
  for (int x : path[u]) add(L[x], 1);
  for (int v : G[u])
    if (v != fa[u][0]) dfs1(v);
  for (auto x : qq[u]) {
    int y = x.first;
    if (query(R[y]) - query(L[y] - 1) > bo[x.second]) ans[x.second]--;
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &fa[i][0]), G[fa[i][0]].push_back(i);
    dep[i] = dep[fa[i][0]] + 1;
    for (int j = 1; j <= 17; j++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  }
  for (int i = 1; i <= n; i++) lag[i] = i;
  scanf("%d", &m);
  for (int i = 1, x, y; i <= m; i++) {
    scanf("%d%d", &x, &y);
    path[x].push_back(y);
    path[y].push_back(x);
    int z = lca(x, y);
    lag[x] = cmax(z, lag[x]);
    lag[y] = cmax(z, lag[y]);
  }
  dfs(1);
  for (int i = 1; i <= n; i++)
    for (int j = 1; j <= 17; j++) g[i][j] = g[g[i][j - 1]][j - 1];
  scanf("%d", &m);
  for (int j = 1, x, y, z; j <= m; j++) {
    scanf("%d%d", &x, &y);
    if (dep[x] < dep[y]) swap(x, y);
    z = lca(x, y);
    if (dep[g[x][17]] > dep[z] || dep[g[y][17]] > dep[z])
      ans[j] = -1;
    else {
      if (z == y) {
        for (int i = 17; i >= 0; i--)
          if (dep[g[x][i]] > dep[y]) x = g[x][i], ans[j] += (1 << i);
        ans[j]++;
      } else {
        for (int i = 17; i >= 0; i--)
          if (dep[g[x][i]] > dep[z]) x = g[x][i], ans[j] += (1 << i);
        for (int i = 17; i >= 0; i--)
          if (dep[g[y][i]] > dep[z]) y = g[y][i], ans[j] += (1 << i);
        ans[j] += 2;
        qq[x].push_back({y, j});
      }
    }
  }
  dfs1(1);
  for (int i = 1; i <= m; i++) printf("%d\n", ans[i]);
  return 0;
}