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;
int tot, n, t, m, fa[200020][19], f[200020][19], la[200020], id[200020],
    pre[200020], ne[200020], deep[200020], tmp[200020], clk, rt[200020], cnt;
vector<int> v[200020];
struct tree {
  int l, r, s;
} tr[200020 * 19];
inline void get(int &x) {
  char c = getchar();
  bool p = 0;
  while ((c < '0' || c > '9') && c != '-') c = getchar();
  if (c == '-') p = 1, c = getchar();
  x = c - '0', c = getchar();
  while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
  if (p) x = -x;
}
struct edge {
  int v, ne;
} e[200020 << 1];
inline void addedge(int u, int v) {
  e[tot].v = v, e[tot].ne = la[u], la[u] = tot++;
}
inline void dfs(int u) {
  id[pre[u] = ++clk] = u;
  for (int i = 1; i < 19; ++i) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = la[u]; ~i; i = e[i].ne) {
    int v = e[i].v;
    if (v == fa[u][0]) continue;
    fa[v][0] = u, deep[v] = deep[u] + 1, dfs(v);
  }
  ne[u] = clk;
}
inline int lca(int u, int v) {
  if (deep[u] < deep[v]) swap(u, v);
  for (int i = 19 - 1; ~i; --i)
    if (deep[fa[u][i]] >= deep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = 19 - 1; ~i; --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
inline bool cmp(int a, int b) { return ne[a] < ne[b]; }
inline void pushup(int o) { tr[o].s = tr[tr[o].l].s + tr[tr[o].r].s; }
inline int update(int o, int l, int r, int x, int v) {
  int no = ++cnt;
  tr[no] = tr[o];
  if (l == r) {
    tr[no].s += v;
    return no;
  }
  int mid = (l + r) >> 1;
  if (x <= mid)
    tr[no].l = update(tr[no].l, l, mid, x, v);
  else
    tr[no].r = update(tr[no].r, mid + 1, r, x, v);
  pushup(no);
  return no;
}
inline int query(int ro, int lo, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return tr[ro].s - tr[lo].s;
  int mid = (l + r) >> 1;
  if (qr <= mid)
    return query(tr[ro].l, tr[lo].l, l, mid, ql, qr);
  else if (ql > mid)
    return query(tr[ro].r, tr[lo].r, mid + 1, r, ql, qr);
  else
    return query(tr[ro].l, tr[lo].l, l, mid, ql, qr) +
           query(tr[ro].r, tr[lo].r, mid + 1, r, ql, qr);
}
void init() {
  cnt = rt[0] = fa[1][0] = clk = tot = 0;
  get(n);
  memset(la, -1, sizeof(la));
  memset(tr, 0, sizeof(tr));
  for (int u = 2; u <= n; ++u) {
    int v;
    get(v);
    addedge(u, v), addedge(v, u);
  }
  deep[1] = 1, dfs(1);
  for (int i = 1; i <= n; ++i) f[i][0] = i, tmp[i] = i;
  get(t);
  for (int i = 1; i <= t; ++i) {
    int x, y;
    get(x), get(y);
    if (pre[x] > pre[y]) swap(x, y);
    int z = lca(x, y);
    if (deep[z] < deep[f[x][0]]) f[x][0] = z;
    if (deep[z] < deep[f[y][0]]) f[y][0] = z;
    v[x].push_back(y);
  }
  std::sort(tmp + 1, tmp + n + 1, cmp);
  for (int i = n; i > 1; --i)
    if (deep[f[fa[i][0]][0]] > deep[f[i][0]]) f[fa[i][0]][0] = f[i][0];
  for (int i = 1; i < 19; ++i)
    for (int u = 1; u <= n; ++u) f[u][i] = f[f[u][i - 1]][i - 1];
  for (int i = 1; i <= n; ++i) {
    rt[i] = rt[i - 1];
    for (int j = 0; j < v[id[i]].size(); ++j)
      rt[i] = update(rt[i], 1, n, pre[v[id[i]][j]], 1);
  }
}
void solve() {
  get(m);
  while (m--) {
    int a, b, ans = 0;
    get(a), get(b);
    if (pre[a] > pre[b]) swap(a, b);
    int c = lca(a, b);
    for (int i = 19 - 1; ~i; --i) {
      if (deep[f[a][i]] > deep[c]) a = f[a][i], ans += (1 << i);
      if (deep[f[b][i]] > deep[c]) b = f[b][i], ans += (1 << i);
    }
    if (ans > n) {
      printf("-1\n");
      continue;
    }
    if (a == c || b == c) {
      printf("%d\n", ans + 1);
      continue;
    }
    printf("%d\n",
           ans + 2 -
               ((bool)(query(rt[ne[a]], rt[pre[a] - 1], 1, n, pre[b], ne[b]))));
  }
}
int main() {
  init();
  solve();
  return 0;
}