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 M = 15000005;
int ls[M], rs[M];
int n, fa[N][20], Fa[N][20];
int dep[N], dfn[N], ed[N];
int rt[N], nd, m, Q;
vector<int> e[N];
vector<int> vec[N];
pair<int, int> t[N];
void insert(int &k, int l, int r, int p) {
  if (!k) k = ++nd;
  if (l == r) return;
  int mid = (l + r) / 2;
  if (p <= mid)
    insert(ls[k], l, mid, p);
  else
    insert(rs[k], mid + 1, r, p);
}
int merge(int x, int y) {
  if (!x || !y) return x + y;
  int k = ++nd;
  ls[k] = merge(ls[x], ls[y]);
  rs[k] = merge(rs[x], rs[y]);
  return k;
}
int ask(int k, int l, int r, int x, int y) {
  if (!k) return 0;
  if (x <= l && r <= y) return 1;
  int mid = (l + r) / 2, ans = 0;
  if (x <= mid) ans |= ask(ls[k], l, mid, x, y);
  if (y > mid) ans |= ask(rs[k], mid + 1, r, x, y);
  return ans;
}
void dfs(int x) {
  dfn[x] = ++*dfn;
  for (auto i : e[x]) dfs(i);
  ed[x] = *dfn;
}
void dfs2(int x) {
  for (auto i : vec[x]) insert(rt[x], 1, n, dfn[i]);
  for (auto i : e[x]) {
    dfs2(i);
    t[x] = min(t[x], t[i]);
    rt[x] = merge(rt[x], rt[i]);
  }
  if (t[x].first >= dep[x])
    Fa[x][0] = x;
  else
    Fa[x][0] = t[x].second;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int tmp = dep[x] - dep[y];
  for (int i = (int)(0); i <= (int)(18); i++)
    if (tmp & (1 << i)) x = fa[x][i];
  for (int i = (int)(18); i >= (int)(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 main() {
  scanf("%d", &n);
  dep[1] = 1;
  for (int i = (int)(1); i <= (int)(n); i++)
    t[i] = pair<int, int>(1 << 30, 1 << 30);
  for (int i = (int)(2); i <= (int)(n); i++) {
    scanf("%d", &fa[i][0]);
    dep[i] = dep[fa[i][0]] + 1;
    e[fa[i][0]].push_back(i);
  }
  dfs(1);
  for (int i = (int)(1); i <= (int)(18); i++)
    for (int j = (int)(1); j <= (int)(n); j++)
      fa[j][i] = fa[fa[j][i - 1]][i - 1];
  scanf("%d", &m);
  for (int i = (int)(1); i <= (int)(m); i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int L = LCA(x, y);
    t[x] = min(t[x], pair<int, int>(dep[L], L));
    t[y] = min(t[y], pair<int, int>(dep[L], L));
    vec[x].push_back(y);
    vec[y].push_back(x);
  }
  dfs2(1);
  for (int i = (int)(1); i <= (int)(18); i++)
    for (int j = (int)(1); j <= (int)(n); j++)
      Fa[j][i] = Fa[Fa[j][i - 1]][i - 1];
  scanf("%d", &Q);
  while (Q--) {
    int x, y;
    scanf("%d%d", &x, &y);
    int L = LCA(x, y);
    if (dep[Fa[x][18]] > dep[L] || dep[Fa[y][18]] > dep[L])
      puts("-1");
    else {
      int ans = 0;
      for (int i = (int)(17); i >= (int)(0); i--)
        if (dep[Fa[x][i]] > dep[L]) x = Fa[x][i], ans += 1 << i;
      for (int i = (int)(17); i >= (int)(0); i--)
        if (dep[Fa[y][i]] > dep[L]) y = Fa[y][i], ans += 1 << i;
      if (x == L || y == L)
        ans++;
      else if (ask(rt[x], 1, n, dfn[y], ed[y]))
        ans++;
      else
        ans += 2;
      printf("%d\n", ans);
    }
  }
}