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 MAXN = 200005;
struct node {
  int l, r, id, op;
} que[MAXN * 5];
int n, m, q, i, j, u, v, lca, cnt, in[MAXN], out[MAXN], dep[MAXN], an[20][MAXN],
    nxt[20][MAXN], ANS[MAXN], ans[MAXN], c[MAXN], f[MAXN];
vector<int> G[MAXN];
inline void read(int &x) {
  short negative = 1;
  x = 0;
  char c = getchar();
  while (c < '0' || c > '9') {
    if (c == '-') negative = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9')
    x = (x << 3) + (x << 1) + (c ^ 48), c = getchar();
  x *= negative;
}
inline void print(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x > 9) print(x / 10);
  putchar(x % 10 + '0');
}
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, int y) {
  if (!x) return;
  while (x <= n) c[x] += y, x += lowbit(x);
}
inline int query(int x) {
  int ans = 0;
  while (x) ans += c[x], x -= lowbit(x);
  return ans;
}
inline int LCA(int u, int v) {
  int i;
  if (dep[u] < dep[v]) std::swap(u, v);
  for (i = 19; i >= 0; i--)
    if (dep[an[i][u]] >= dep[v]) u = an[i][u];
  if (u == v) return u;
  for (i = 19; i >= 0; i--)
    if (an[i][u] != an[i][v]) u = an[i][u], v = an[i][v];
  return f[u];
}
inline void dfs(int u) {
  dep[u] = dep[f[u]] + 1;
  in[u] = ++cnt;
  for (int i = 0; i < G[u].size(); i++) dfs(G[u][i]);
  out[u] = cnt;
}
inline void dfs2(int u) {
  for (int i = 0; i < G[u].size(); i++) {
    int v = G[u][i];
    dfs2(v);
    if (!nxt[0][u] || nxt[0][v] && dep[nxt[0][v]] < dep[nxt[0][u]])
      nxt[0][u] = nxt[0][v];
  }
  if (dep[nxt[0][u]] >= dep[u]) nxt[0][u] = 0;
}
inline bool cmp(node a, node b) {
  return a.l < b.l || (a.l == b.l && a.id < b.id);
}
signed main(void) {
  read(n);
  for (i = 2; i <= n; i++) {
    read(f[i]);
    G[f[i]].push_back(i);
    an[0][i] = f[i];
  }
  dfs(1);
  for (j = 1; j < 20; j++)
    for (i = 1; i <= n; i++) an[j][i] = an[j - 1][an[j - 1][i]];
  read(m);
  for (i = 1, cnt = 0; i <= m; i++) {
    read(u), read(v);
    if (in[u] > in[v]) std::swap(u, v);
    lca = LCA(u, v);
    if (dep[lca] < dep[nxt[0][u]] || !nxt[0][u]) nxt[0][u] = lca;
    if (dep[lca] < dep[nxt[0][v]] || !nxt[0][v]) nxt[0][v] = lca;
    que[++cnt] = node{in[u], in[v], 0, 1};
  }
  dfs2(1);
  for (j = 1; j < 20; j++)
    for (i = 1; i <= n; i++) nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];
  read(q);
  for (i = 1; i <= q; i++) {
    read(u), read(v);
    lca = LCA(u, v);
    if (in[u] > in[v]) swap(u, v);
    for (j = 19; j >= 0; j--)
      if (nxt[j][u] && dep[nxt[j][u]] > dep[lca])
        u = nxt[j][u], ans[i] += (1 << j);
    for (j = 19; j >= 0; j--)
      if (nxt[j][v] && dep[nxt[j][v]] > dep[lca])
        v = nxt[j][v], ans[i] += (1 << j);
    if ((!nxt[0][u] && u != lca) || (!nxt[0][v] && v != lca)) {
      ans[i] = -1;
      continue;
    }
    if (u == lca || v == lca) {
      ans[i]++;
      continue;
    }
    ans[i] += 2;
    que[++cnt] = node{out[u], out[v], i, 1};
    que[++cnt] = node{in[u] - 1, out[v], i, -1};
    que[++cnt] = node{out[u], in[v] - 1, i, -1};
    que[++cnt] = node{in[u] - 1, in[v] - 1, i, 1};
  }
  sort(que + 1, que + cnt + 1, cmp);
  for (i = 1; i <= cnt; i++)
    if (!que[i].id)
      add(que[i].r, 1);
    else
      ANS[que[i].id] += que[i].op * query(que[i].r);
  for (i = 1; i <= q; i++) print(ans[i] - (ANS[i] > 0)), putchar('\n');
  return 0;
}