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;
void read(int &n) {
  n = 0;
  int s = 1;
  char c;
  for (; (c = getchar()) > '9' || c < '0';)
    if (c == '-') s = -1;
  for (; c >= '0' && c <= '9'; c = getchar()) n = (n << 1) + (n << 3) + c - 48;
  n *= s;
}
void write(int n) {
  if (!n) putchar(48);
  int t = 0, b[20];
  for (; n; n /= 10) b[++t] = n % 10;
  while (t) putchar(b[t--] + 48);
}
int f[18][200100], nxt[18][200100], m, n, q, deep[200100], fir[200100],
    nex[200100], to[200100], top, son[10001001][2], siz[10001001], cnt,
    rt[200100], dfl[200100], dfr[200100], mn[200100], opl, opr;
struct dot {
  int a, b;
} a[200100 + 200100];
bool cmp(dot a, dot b) { return a.a < b.a; }
void dfs(int x) {
  ++deep[x];
  dfl[x] = dfr[x] = ++top;
  for (int i = fir[x]; i; i = nex[i])
    deep[to[i]] = deep[x], dfs(to[i]), dfr[x] = dfr[to[i]];
}
int lca(int x, int y) {
  if (deep[x] > deep[y]) return lca(y, x);
  for (int i(17), _E_(0); i >= _E_; --i)
    if (deep[f[i][y]] >= deep[x]) y = f[i][y];
  if (x == y) return x;
  for (int i(17), _E_(0); i >= _E_; --i)
    if (f[i][y] ^ f[i][x]) x = f[i][x], y = f[i][y];
  return f[0][x];
}
void doit(int x) {
  for (int i = fir[x]; i; i = nex[i]) {
    doit(to[i]);
    mn[x] = deep[mn[to[i]]] < deep[mn[x]] ? mn[to[i]] : mn[x];
  }
  if (x ^ mn[x]) nxt[0][x] = mn[x];
}
void update(int u, int &v, int h, int t) {
  v = ++cnt;
  siz[v] = siz[u] + 1;
  son[v][0] = son[u][0];
  son[v][1] = son[u][1];
  if (h == t) return;
  int m = h + t >> 1;
  if (opl <= m)
    update(son[u][0], son[v][0], h, m);
  else
    update(son[u][1], son[v][1], m + 1, t);
}
int query(int w, int h, int t) {
  if (opl > t || opr < h || !w) return 0;
  if (opl <= h && opr >= t) return siz[w];
  int m = h + t >> 1, res = 0;
  if (opl <= m) res += query(son[w][0], h, m);
  if (opr > m) res += query(son[w][1], m + 1, t);
  return res;
}
int exist(int u, int v) {
  int sum = 0;
  opr = dfr[v];
  opl = dfl[v];
  sum += query(rt[dfr[u]], 1, n);
  opr = dfr[v];
  opl = dfl[v];
  sum -= query(rt[dfl[u] - 1], 1, n);
  return sum > 0;
}
int main() {
  scanf("%d", &n);
  for (int i(1), _E_(n); i <= _E_; ++i) mn[i] = i;
  for (int i(2), _E_(n); i <= _E_; ++i)
    scanf("%d", f[0] + i), to[++top] = i, nex[top] = fir[f[0][i]],
                           fir[f[0][i]] = top;
  top = 0;
  dfs(1);
  scanf("%d", &m);
  for (int j(1), _E_(17); j <= _E_; ++j)
    for (int i(1), _E_(n); i <= _E_; ++i) f[j][i] = f[j - 1][f[j - 1][i]];
  int t = 0;
  for (int i(1), _E_(m); i <= _E_; ++i) {
    int x, y, l;
    scanf("%d %d", &x, &y);
    l = lca(x, y);
    a[++t] = (dot){dfl[x], dfl[y]};
    a[++t] = (dot){dfl[y], dfl[x]};
    mn[x] = deep[mn[x]] > deep[l] ? l : mn[x];
    mn[y] = deep[mn[y]] > deep[l] ? l : mn[y];
  }
  doit(1);
  sort(a + 1, a + m + m + 1, cmp);
  for (int j(1), _E_(17); j <= _E_; ++j)
    for (int i(1), _E_(n); i <= _E_; ++i) nxt[j][i] = nxt[j - 1][nxt[j - 1][i]];
  for (int i(1), _E_(m + m); i <= _E_; ++i)
    opl = a[i].b, update(rt[a[i - 1].a], rt[a[i].a], 1, n);
  for (int i(1), _E_(n); i <= _E_; ++i)
    if (!rt[i]) rt[i] = rt[i - 1];
  scanf("%d", &q);
  for (int i(1), _E_(q); i <= _E_; ++i) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (u == v) {
      printf("0\n");
      continue;
    }
    int L = lca(u, v), ans = 0;
    for (int j(17), _E_(0); j >= _E_; --j)
      if (deep[nxt[j][u]] > deep[L]) u = nxt[j][u], ans += 1 << j;
    for (int j(17), _E_(0); j >= _E_; --j)
      if (deep[nxt[j][v]] > deep[L]) v = nxt[j][v], ans += 1 << j;
    if (L == u && nxt[0][v])
      printf("%d\n", ans + 1);
    else if (L == v && nxt[0][u])
      printf("%d\n", ans + 1);
    else if (!nxt[0][u] || !nxt[0][v])
      printf("-1\n");
    else
      printf("%d\n", ans + 2 - exist(u, v));
  }
  return 0;
}