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 + 5;
int n, m, Q, g[N][30], fa[N][30];
struct ques {
  int x, y, id, opt;
} q[N << 3];
struct node {
  int to, nxt;
} e[N << 1];
int head[N], cnt, ans[N], Ans[N];
inline void add(int u, int v) {
  e[++cnt].to = v;
  e[cnt].nxt = head[u];
  head[u] = cnt;
}
int l[N], r[N], tot, dep[N];
inline void dfs(int u, int f) {
  dep[u] = dep[f] + 1;
  fa[u][0] = f;
  l[u] = ++tot;
  for (int i = 1; i <= 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == f) continue;
    dfs(v, u);
  }
  r[u] = tot;
}
inline int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = 20; i >= 0 && dep[u] > dep[v]; i--) {
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  }
  if (u == v) return u;
  for (int i = 20; i >= 0; i--) {
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  }
  return fa[u][0];
}
inline void dfs2(int u, int f) {
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == f) continue;
    dfs2(v, u);
    if (!g[u][0] || (g[v][0] && dep[g[v][0]] < dep[g[u][0]])) g[u][0] = g[v][0];
  }
}
inline bool cmp(ques i, ques j) {
  if (i.x != j.x) return i.x < j.x;
  return i.id < j.id;
}
int tr[N];
inline void update(int x) {
  while (x <= n) tr[x]++, x += x & -x;
}
inline int query(int x) {
  int ret = 0;
  while (x) ret += tr[x], x -= x & -x;
  return ret;
}
int main() {
  scanf("%d", &n);
  for (int i = 2, x; i <= n; i++) {
    scanf("%d", &x);
    add(x, i);
  }
  dfs(1, 0);
  scanf("%d", &m);
  tot = 0;
  for (int i = 1, u, v; i <= m; i++) {
    scanf("%d%d", &u, &v);
    if (l[u] > l[v]) swap(u, v);
    int L = lca(u, v);
    if (!g[u][0] || dep[L] < dep[g[u][0]]) g[u][0] = L;
    if (!g[v][0] || dep[L] < dep[g[v][0]]) g[v][0] = L;
    q[++tot] = (ques){l[u], l[v], 0, 0};
  }
  dfs2(1, 0);
  for (int i = 1; i <= n; i++)
    if (g[i][0] == i) g[i][0] = 0;
  for (int i = 1; i <= 20; i++)
    for (int u = 1; u <= n; u++) g[u][i] = g[g[u][i - 1]][i - 1];
  scanf("%d", &Q);
  for (int i = 1, u, v; i <= Q; i++) {
    scanf("%d%d", &u, &v);
    if (l[u] > l[v]) swap(u, v);
    int L = lca(u, v);
    for (int j = 20; j >= 0; j--)
      if (dep[g[u][j]] > dep[L]) u = g[u][j], ans[i] += (1 << j);
    for (int j = 20; j >= 0; j--)
      if (dep[g[v][j]] > dep[L]) v = g[v][j], ans[i] += (1 << j);
    if ((!g[u][0] && u != L) || (!g[v][0] && v != L)) {
      ans[i] = -1;
      continue;
    }
    if (u == L || v == L)
      ans[i]++;
    else {
      ans[i] += 2;
      q[++tot] = (ques){l[u] - 1, l[v] - 1, i, 1};
      q[++tot] = (ques){l[u] - 1, r[v], i, -1};
      q[++tot] = (ques){r[u], l[v] - 1, i, -1};
      q[++tot] = (ques){r[u], r[v], i, 1};
    }
  }
  sort(q + 1, q + 1 + tot, cmp);
  for (int i = 1; i <= tot; i++) {
    if (!q[i].id)
      update(q[i].y);
    else
      Ans[q[i].id] += q[i].opt * query(q[i].y);
  }
  for (int i = 1; i <= Q; i++) {
    if (Ans[i]) ans[i]--;
    printf("%d\n", ans[i]);
  }
  return 0;
}