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 + 10, M = 4e5 + 10, T = 17;
int to[M], nx[M], ls[N], vl[M], num = 0;
void link(int u, int v) { to[++num] = v, nx[num] = ls[u], ls[u] = num; }
struct node {
  int x, y, p, t;
} a[M], b[M << 2];
int an[M], cn[M];
int fa[N][T + 3], f[N][T + 3];
int L[N], R[N], tot = 0;
int dep[N];
bool bz[M];
void pre(int x, int fr) {
  dep[x] = dep[fr] + 1, L[x] = ++tot;
  for (int i = 1; i <= T; ++i) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = ls[x]; i; i = nx[i]) pre(to[i], x);
  R[x] = tot;
}
void pre2(int x) {
  for (int i = ls[x]; i; i = nx[i]) {
    int v = to[i];
    pre2(v);
    if (dep[f[x][0]] > dep[f[v][0]]) f[x][0] = f[v][0];
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = T; i >= 0; --i)
    if (dep[fa[u][i]] >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = T; i >= 0; --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
bool cmp(node x, node y) { return x.x < y.x; }
int tr[N], n;
void add(int x) {
  for (; x <= n; x += x & -x) tr[x]++;
}
int sum(int x) {
  int tmp = 0;
  for (; x; x -= x & -x) tmp += tr[x];
  return tmp;
}
void cr(int x, int y, int p, int t) {
  b[++tot].x = x, b[tot].y = y, b[tot].p = p, b[tot].t = t;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) scanf("%d", &fa[i][0]), link(fa[i][0], i);
  pre(1, 0);
  int m;
  scanf("%d", &m);
  for (int i = 1; i <= n; ++i) f[i][0] = i;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (L[u] > L[v]) swap(u, v);
    int lc = lca(u, v);
    if (dep[f[u][0]] > dep[lc]) f[u][0] = lc;
    if (dep[f[v][0]] > dep[lc]) f[v][0] = lc;
    a[i].x = L[u], a[i].y = L[v], a[i].t = 0;
  }
  pre2(1);
  for (int i = 1; i <= n; ++i)
    if (f[i][0] == i) f[i][0] = 0;
  for (int j = 1; j <= T; ++j)
    for (int i = 1; i <= n; ++i) f[i][j] = f[f[i][j - 1]][j - 1];
  int q;
  scanf("%d", &q);
  tot = 0;
  for (int i = 1; i <= q; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (u == v) {
      an[i] = 0;
      continue;
    }
    if (dep[u] < dep[v]) swap(u, v);
    int lc = lca(u, v), t = 0;
    if (lc == v) {
      for (int j = T; j >= 0; --j)
        if (dep[f[u][j]] > dep[v]) u = f[u][j], t += 1 << j;
      if (!f[u][0]) {
        an[i] = -1;
        continue;
      }
      an[i] = ++t;
      continue;
    }
    for (int j = T; j >= 0; --j)
      if (dep[f[u][j]] > dep[lc]) u = f[u][j], t += 1 << j;
    for (int j = T; j >= 0; --j)
      if (dep[f[v][j]] > dep[lc]) v = f[v][j], t += 1 << j;
    if (!f[u][0] || !f[v][0]) {
      an[i] = -1;
      continue;
    }
    bz[i] = 1;
    an[i] = t + 1;
    if (L[u] > L[v]) swap(u, v);
    cr(R[u], R[v], i, 1);
    cr(L[u] - 1, R[v], i, -1);
    cr(R[u], L[v] - 1, i, -1);
    cr(L[u] - 1, L[v] - 1, i, 1);
  }
  sort(a + 1, a + m + 1, cmp), sort(b + 1, b + tot + 1, cmp);
  int p = 0;
  for (int i = 1; i <= tot; ++i) {
    while (p < m && a[p + 1].x <= b[i].x) add(a[++p].y);
    cn[b[i].p] += sum(b[i].y) * b[i].t;
  }
  for (int i = 1; i <= q; ++i)
    if (bz[i]) an[i] += cn[i] == 0;
  for (int i = 1; i <= q; ++i) printf("%d\n", an[i]);
}