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 = 200005;
const int D = 30;
struct node {
  int a, b;
};
vector<int> road[N], h[N];
vector<node> q[N];
int n, m, t, fa[N][D + 1], w[N][D + 1], head[N], sum[N], ans[N], g[N];
int cnt, tot, dep[N], id[N], size[N], c[N];
int lowbit(int x) { return x & -x; }
void update(int x) {
  for (int i = x; i <= n; i += lowbit(i)) {
    c[i] += 1;
  }
}
int check(int x) {
  int tmp = 0;
  for (int i = x; i >= 1; i -= lowbit(i)) {
    tmp += c[i];
  }
  return tmp;
}
struct edge {
  int to, nxt;
} e[N * 2];
void add(int u, int v) {
  cnt++;
  e[cnt].nxt = head[u];
  e[cnt].to = v;
  head[u] = cnt;
}
void dfs1(int u, int deep) {
  dep[u] = deep;
  id[u] = ++tot;
  size[u] = 1;
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa[u][0]) continue;
    dfs1(v, deep + 1);
    size[u] += size[v];
  }
}
void dfs2(int u) {
  g[u] = u;
  for (int i = 0; i < h[u].size(); i++) {
    if (dep[h[u][i]] < dep[g[u]]) g[u] = h[u][i];
  }
  for (int i = head[u]; i; i = e[i].nxt) {
    int v = e[i].to;
    if (v == fa[u][0]) continue;
    dfs2(v);
    if (dep[g[v]] < dep[g[u]]) g[u] = g[v];
  }
  w[u][0] = g[u];
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = D; i >= 0; i--) {
    if (dep[fa[x][i]] >= dep[y]) x = fa[x][i];
  }
  if (x == y) return x;
  for (int i = D; i >= 0; i--) {
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  }
  return fa[x][0];
}
node work(int x, int LCA) {
  if (x == LCA) return (node){x, 0};
  int tmp = 0;
  for (int i = D; i >= 0; i--)
    if (dep[w[x][i]] > dep[LCA]) x = w[x][i], tmp += (1 << i);
  if (w[x][0] == x) return (node){x, -1};
  return (node){x, tmp};
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &fa[i][0]);
    add(fa[i][0], i);
    add(i, fa[i][0]);
  }
  dfs1(1, 1);
  for (int i = 1; i <= D; 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);
    int c = lca(x, y);
    if (id[x] > id[y]) swap(x, y);
    road[id[x]].push_back(id[y]);
    if (dep[c] < dep[x]) h[x].push_back(c);
    if (dep[c] < dep[y]) h[y].push_back(c);
  }
  dfs2(1);
  for (int i = 1; i <= n; i++) {
  }
  for (int i = 1; i <= D; i++)
    for (int j = 1; j <= n; j++) {
      w[j][i] = w[w[j][i - 1]][i - 1];
    }
  scanf("%d", &t);
  for (int i = 1; i <= t; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int c = lca(x, y);
    node A = work(x, c);
    node B = work(y, c);
    if (A.b == -1 || B.b == -1) {
      ans[i] = -1;
      continue;
    }
    if (x == c || y == c) {
      ans[i] = A.b + B.b + 1;
      continue;
    }
    ans[i] = A.b + B.b + 2;
    x = A.a;
    y = B.a;
    if (id[x] > id[y]) swap(x, y);
    q[id[x] - 1].push_back((node){y, -i});
    q[id[x] + size[x] - 1].push_back((node){y, i});
  }
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < road[i].size(); j++) update(road[i][j]);
    for (int j = 0; j < q[i].size(); j++) {
      int num = (q[i][j].b > 0 ? 1 : -1);
      int x = q[i][j].a;
      int y = q[i][j].b * num;
      sum[y] += num * (check(id[x] + size[x] - 1) - check(id[x] - 1));
    }
  }
  for (int i = 1; i <= t; i++) {
    printf("%d\n", ans[i] - (sum[i] > 0));
  }
  return 0;
}