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 n, m, lev[200010], paa[200010][20], mina[200010], ti, lf[200010],
    rg[200010], dfa[200010];
vector<int> mat[200010], co[200010], pos[200010], route[200010];
void dfs(int p, int pa) {
  if (p == pa) ti = 0;
  lf[p] = ++ti;
  dfa[ti] = p;
  for (auto x : mat[p]) {
    if (x == pa) continue;
    paa[x][0] = p;
    lev[x] = lev[p] + 1;
    dfs(x, p);
    if (lev[mina[p]] > lev[mina[x]]) mina[p] = mina[x];
  }
  rg[p] = ti;
}
void sparceTable() {
  for (int i = 1; i <= 19; i++)
    for (int p = 1; p <= n; p++) {
      int go = paa[p][i - 1];
      if (go != -1) paa[p][i] = paa[go][i - 1];
    }
}
int levPa(int p, int l, int bs) {
  if (lev[p] == l || bs == -1) return p;
  int go = paa[p][bs];
  if (go != -1 && lev[go] >= l)
    return levPa(go, l, bs);
  else
    return levPa(p, l, bs - 1);
}
int lca(int f, int s, int bs) {
  if (bs == -1) return paa[f][0];
  int go = paa[f][bs], so = paa[s][bs];
  if (go != so)
    return lca(go, so, bs);
  else
    return lca(f, s, bs - 1);
}
int finLca(int f, int s) {
  if (lev[f] < lev[s]) swap(f, s);
  f = levPa(f, lev[s], 19);
  if (f == s)
    return f;
  else
    return lca(f, s, 19);
}
int can(int p, int tar) {
  if (lev[p] <= lev[tar]) return 0;
  if (mina[p] == p) return -200010;
  return 1 + can(mina[p], tar);
}
int jump(int p, int j) {
  if (j <= 0) return p;
  return jump(mina[p], j - 1);
}
int prin[200010], value[200010];
pair<int, int> poo[200010];
int tree[4 * 200010];
void update(int idx, int b, int e, int p, int val) {
  if (b > p || e < p) return;
  if (b == e) {
    tree[idx] = val;
    return;
  }
  int mid = (b + e) >> 1;
  update((idx << 1), b, mid, p, val);
  update((idx << 1) + 1, mid + 1, e, p, val);
  tree[idx] = tree[(idx << 1)] + tree[(idx << 1) + 1];
  return;
}
int query(int idx, int b, int e, int st, int en) {
  if (b > en || e < st) return 0;
  if (st <= b && e <= en) return tree[idx];
  int mid = (b + e) >> 1;
  return query((idx << 1), b, mid, st, en) +
         query((idx << 1) + 1, mid + 1, e, st, en);
}
int sz[200010], bigChild[200010], nex[200010], dhur[200010];
void dsudfs(int p, int pa) {
  sz[p] = route[p].size();
  int mx = -1;
  bigChild[p] = -1;
  for (auto x : mat[p]) {
    if (x != pa) {
      dsudfs(x, p);
      sz[p] += sz[x];
      if (sz[x] > mx) mx = sz[x], bigChild[p] = x;
    }
  }
}
int finNex(int p) {
  if (p == nex[p])
    return p;
  else
    return nex[p] = finNex(nex[p]);
}
void up(int p, int v) {
  int l = lf[p];
  while (l <= rg[p]) {
    int x = dfa[l];
    for (auto y : route[x]) {
      update(1, 1, 200010, lf[y], v);
    }
    if (route[x].size() == 0) nex[l - 1] = l;
    l = nex[l] + 1;
  }
}
void dsu(int p, int pa, int keep) {
  for (auto x : mat[p])
    if (x != pa && x != bigChild[p]) dsu(x, p, 0);
  if (bigChild[p] != -1) dsu(bigChild[p], p, 1);
  for (auto x : route[p]) update(1, 1, 200010, lf[x], 1);
  for (auto x : mat[p]) {
    if (x == pa || x == bigChild[p]) continue;
    up(x, 1);
  }
  int lol = 0, y;
  for (auto x : co[p]) {
    y = pos[p][lol];
    lol++;
    if (query(1, 1, 200010, lf[x], rg[x])) prin[y]--;
  }
  if (!keep) up(p, 0);
}
int main() {
  int x, y;
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &x);
    mat[x].push_back(i);
    mat[i].push_back(x);
  }
  memset(paa, -1, sizeof(paa));
  dfs(1, 1);
  sparceTable();
  int q, lc, a, b;
  scanf("%d", &q);
  for (int i = 1; i <= n; i++) mina[i] = i;
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    lc = finLca(x, y);
    if (lev[mina[x]] > lev[lc]) mina[x] = lc;
    if (lev[mina[y]] > lev[lc]) mina[y] = lc;
    route[x].push_back(y);
    route[y].push_back(x);
  }
  dfs(1, 1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    scanf("%d %d", &x, &y);
    lc = finLca(x, y);
    a = can(x, lc);
    b = can(y, lc);
    if (a < 0 || b < 0) {
      prin[i] = -1;
    } else {
      prin[i] = a + b;
      a = jump(x, a - 1);
      b = jump(y, b - 1);
      if (lc != x && lc != y) {
        co[a].push_back(b);
        pos[a].push_back(i);
      }
    }
  }
  dsudfs(1, 1);
  for (int i = lf[1]; i <= rg[1]; i++) nex[i] = i;
  dsu(1, 1, 0);
  for (int i = 1; i <= q; i++) {
    printf("%d\n", prin[i]);
  }
  return 0;
}