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 = 200100;
const int N_FenTree = 400100;
const int M = 23;
int n, m, q, cnt, tme;
vector<int> bus[N], tmp[N];
vector<pair<int, int> > query[N];
int start[N], nxt[N * 2], to[N * 2], dep[N], fa[N][M], high[N][M], timein[N],
    timeout[N], ans[N];
void add(int x, int y) {
  nxt[++cnt] = start[x];
  to[cnt] = y;
  start[x] = cnt;
}
struct FenTree {
  int c1[N_FenTree], c2[N_FenTree];
  void ptAdd(int pos, int x) {
    for (int i = pos; i <= N_FenTree; i += i & (-i)) {
      c1[i] += x;
      c2[i] += x * pos;
    }
  }
  int ptSum(int pos) {
    int RV = 0;
    for (int i = pos; i; i -= i & (-i)) RV += (pos + 1) * c1[i] - c2[i];
    return RV;
  }
  void add(int l1, int l2, int val) {
    ptAdd(l1, val);
    ptAdd(l2 + 1, -val);
  }
  int sum(int l, int r) { return ptSum(r) - ptSum(l - 1); }
} tree;
void dfs(int cur) {
  timein[cur] = ++tme;
  for (int i = start[cur]; i; i = nxt[i])
    if (!dep[to[i]]) {
      dep[to[i]] = dep[cur] + 1;
      fa[to[i]][0] = cur;
      dfs(to[i]);
    }
  timeout[cur] = ++tme;
}
void dfs2(int cur) {
  for (int i = start[cur]; i; i = nxt[i])
    if (dep[to[i]] > dep[cur]) dfs2(to[i]);
  if (high[fa[cur][0]][0] == 0 || dep[high[cur][0]] < dep[high[fa[cur][0]][0]])
    high[fa[cur][0]][0] = high[cur][0];
}
void dfs3(int cur) {
  tmp[cur].resize(query[cur].size());
  for (int i = 0; i < query[cur].size(); i++)
    tmp[cur][i] =
        tree.sum(timein[query[cur][i].first], timeout[query[cur][i].first]);
  for (int i = start[cur]; i; i = nxt[i])
    if (dep[to[i]] > dep[cur]) dfs3(to[i]);
  for (int num : bus[cur]) tree.add(timein[num], timein[num], 1);
  for (int i = 0; i < query[cur].size(); i++)
    if (tmp[cur][i] !=
        tree.sum(timein[query[cur][i].first], timeout[query[cur][i].first]))
      ans[query[cur][i].second]--;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = M - 1; i >= 0; i--)
    if (fa[x][i] && dep[fa[x][i]] > dep[y]) x = fa[x][i];
  if (dep[x] != dep[y]) x = fa[x][0];
  for (int i = M - 1; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return x == y ? x : fa[x][0];
}
int cost(int x, int y) {
  if (x == y) return 0;
  int RV = 0;
  for (int i = M - 1; i >= 0; i--)
    if (high[x][i] && dep[high[x][i]] > dep[y]) x = high[x][i], RV += (1 << i);
  if (high[x][0] && dep[high[x][0]] <= dep[y]) return RV + 1;
  return -0x3f3f3f3f;
}
int get(int x, int cnt) {
  for (int i = 0; cnt; i++)
    if (cnt & 1 << i) cnt ^= 1 << i, x = high[x][i];
  return x;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    add(x, i);
    add(i, x);
  }
  dep[1] = 1;
  dep[0] = 0x3f3f3f3f;
  dfs(1);
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= n; j++) fa[j][i] = fa[fa[j][i - 1]][i - 1];
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    if (timein[x] < timein[y])
      bus[x].push_back(y);
    else
      bus[y].push_back(x);
    int LCA = lca(x, y);
    if (!high[x][0] || dep[high[x][0]] > dep[LCA]) high[x][0] = LCA;
    if (!high[y][0] || dep[high[y][0]] > dep[LCA]) high[y][0] = LCA;
  }
  dfs2(1);
  for (int i = 1; i < M; i++)
    for (int j = 1; j <= n; j++) high[j][i] = high[high[j][i - 1]][i - 1];
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int LCA = lca(x, y);
    int c1 = cost(x, LCA), c2 = cost(y, LCA);
    if (c1 < 0 || c2 < 0)
      ans[i] = -1;
    else {
      ans[i] = c1 + c2;
      if (x == LCA || y == LCA) continue;
      x = get(x, c1 - 1);
      y = get(y, c2 - 1);
      if (timein[x] < timein[y])
        query[x].push_back({y, i});
      else
        query[y].push_back({x, i});
    }
  }
  dfs3(1);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}