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 = 2e5 + 10;
inline long long rd() {
  long long x = 0;
  char c = getchar();
  int neg = 1;
  while (c < '0' || c > '9') {
    if (c == '-') neg = -1;
    c = getchar();
  }
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  return x * neg;
}
int eg[maxn][2], egh[maxn], ect;
int N, M, Q, dep[maxn], fa[maxn][22], nxt[maxn][22];
int dfn[maxn][2], tot, ans[maxn];
int pt[maxn * 2][2], pth[maxn], tr[maxn];
int lq[maxn * 2][2], lqh[maxn], tmp[maxn * 2];
bool covered[maxn];
inline void adeg(int a, int b) {
  eg[++ect][0] = b, eg[ect][1] = egh[a], egh[a] = ect;
}
void dfs(int x) {
  dfn[x][0] = ++tot;
  for (int i = 0; fa[x][i] && fa[fa[x][i]][i]; i++)
    fa[x][i + 1] = fa[fa[x][i]][i];
  for (int i = egh[x]; i; i = eg[i][1]) {
    int b = eg[i][0];
    dep[b] = dep[x] + 1;
    dfs(b);
  }
  dfn[x][1] = tot;
}
int getlca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i >= 0 && dep[x] != dep[y]; i--) {
    if (fa[x][i] && dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  }
  if (x == y) return x;
  for (int i = 19; i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  }
  return fa[x][0];
}
void dfs2(int x) {
  for (int i = egh[x]; i; i = eg[i][1]) {
    int b = eg[i][0];
    dfs2(b);
    if (nxt[b][0] && (dep[nxt[b][0]] < dep[nxt[x][0]] || !nxt[x][0]))
      nxt[x][0] = nxt[b][0];
  }
  if (dep[nxt[x][0]] >= dep[x]) nxt[x][0] = 0;
}
inline int lowbit(int x) { return x & (-x); }
inline void add(int x, int y) {
  for (; x <= N; x += lowbit(x)) tr[x] += y;
}
inline int query(int x) {
  int re = 0;
  for (; x; x -= lowbit(x)) re += tr[x];
  return re;
}
void dfs3(int x) {
  for (int i = lqh[x]; i; i = lq[i][1]) {
    int b = lq[i][0];
    tmp[i] = query(dfn[b][1]) - query(dfn[b][0] - 1);
  }
  for (int i = pth[x]; i; i = pt[i][1]) {
    int b = pt[i][0];
    add(dfn[b][0], 1);
  }
  for (int i = egh[x]; i; i = eg[i][1]) {
    int b = eg[i][0];
    dfs3(b);
  }
  for (int i = lqh[x]; i; i = lq[i][1]) {
    int b = lq[i][0];
    if (tmp[i] != query(dfn[b][1]) - query(dfn[b][0] - 1)) covered[i >> 1] = 1;
  }
}
int main() {
  int i, j, k;
  N = rd();
  for (i = 2; i <= N; i++) {
    fa[i][0] = rd();
    adeg(fa[i][0], i);
  }
  dep[1] = 1;
  dfs(1);
  M = rd();
  for (i = 1; i <= M; i++) {
    int a = rd(), b = rd();
    pt[i << 1][0] = a, pt[i << 1][1] = pth[b], pth[b] = i << 1;
    pt[i << 1 | 1][0] = b, pt[i << 1 | 1][1] = pth[a], pth[a] = i << 1 | 1;
    int x = getlca(a, b);
    if (dep[x] < dep[nxt[a][0]] || !nxt[a][0]) nxt[a][0] = x;
    if (dep[x] < dep[nxt[b][0]] || !nxt[b][0]) nxt[b][0] = x;
  }
  dfs2(1);
  for (i = 0; i < 19; i++) {
    for (j = 1; j <= N; j++) {
      nxt[j][i + 1] = nxt[nxt[j][i]][i];
    }
  }
  Q = rd();
  for (i = 1; i <= Q; i++) {
    int a = rd(), b = rd(), lca = getlca(a, b);
    for (j = 19; j >= 0; j--) {
      if (nxt[a][j] && dep[nxt[a][j]] > dep[lca])
        ans[i] += 1 << j, a = nxt[a][j];
    }
    for (j = 19; j >= 0; j--) {
      if (nxt[b][j] && dep[nxt[b][j]] > dep[lca])
        ans[i] += 1 << j, b = nxt[b][j];
    }
    if ((a == lca && nxt[b][0] && dep[nxt[b][0]] <= dep[lca]) ||
        (b == lca && nxt[a][0] && dep[nxt[a][0]] <= dep[lca]))
      ans[i] += 1;
    else if (nxt[a][0] && nxt[b][0] && dep[nxt[a][0]] <= dep[lca] &&
             dep[nxt[b][0]] <= dep[lca]) {
      ans[i] += 2;
      lq[i << 1][0] = a, lq[i << 1][1] = lqh[b], lqh[b] = i << 1;
      lq[i << 1 | 1][0] = b, lq[i << 1 | 1][1] = lqh[a], lqh[a] = i << 1 | 1;
    } else {
      ans[i] = -1;
    }
  }
  dfs3(1);
  for (i = 1; i <= Q; i++) printf("%d\n", ans[i] - covered[i]);
  return 0;
}