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 ___[400050], _____, ______[400050], _______;
struct edge {
  int x, y, p, t;
} a[400050], b[400050 * 4];
struct node {
  int to, next;
} _________[400050 * 4];
int an[400050], cn[400050], __________[400050][20], ___________[400050][20],
    L[400050], R[400050], tot = 0, ____________[400050], bz[400050];
void link(int u, int v) {
  _________[++_______] = (node){v, ______[u]};
  ______[u] = _______;
}
void ________(int u, int ___________) {
  ____________[u] = ____________[___________] + 1, L[u] = ++tot;
  for (int _____________ = 1; _____________ <= 17; _____________++)
    __________[u][_____________] =
        __________[__________[u][_____________ - 1]][_____________ - 1];
  for (int _____________ = ______[u]; _____________;
       _____________ = _________[_____________].next)
    ________(_________[_____________].to, u);
  R[u] = tot;
}
void dfs2(int x) {
  for (int _____________ = ______[x]; _____________;
       _____________ = _________[_____________].next) {
    int v = _________[_____________].to;
    dfs2(v);
    if (____________[___________[x][0]] > ____________[___________[v][0]])
      ___________[x][0] = ___________[v][0];
  }
}
int lca(int u, int v) {
  if (____________[u] < ____________[v]) swap(u, v);
  for (int _____________ = 17; _____________ >= 0; _____________--)
    if (____________[__________[u][_____________]] >= ____________[v])
      u = __________[u][_____________];
  if (u == v) return u;
  for (int _____________ = 17; _____________ >= 0; _____________--)
    if (__________[u][_____________] != __________[v][_____________])
      u = __________[u][_____________], v = __________[v][_____________];
  return __________[u][0];
}
bool cmp(edge x, edge y) { return x.x < y.x; }
int tr[400050], _;
void add(int x) {
  for (; x <= _; x += x & -x) tr[x]++;
}
int sum(int x) {
  int tmp = 0;
  for (; x; x -= x & -x) tmp += tr[x];
  return tmp;
}
int main() {
  scanf("%d", &_);
  for (int _____________ = 2; _____________ <= _; _____________++)
    scanf("%d", &__________[_____________][0]),
        link(__________[_____________][0], _____________);
  ________(1, 0);
  int __;
  scanf("%d", &__);
  for (int _____________ = 1; _____________ <= _; _____________++)
    ___________[_____________][0] = _____________;
  for (int _____________ = 1; _____________ <= __; _____________++) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (L[u] > L[v]) swap(u, v);
    int lc = lca(u, v);
    if (____________[___________[u][0]] > ____________[lc])
      ___________[u][0] = lc;
    if (____________[___________[v][0]] > ____________[lc])
      ___________[v][0] = lc;
    a[_____________].x = L[u], a[_____________].y = L[v],
    a[_____________].t = 0;
  }
  dfs2(1);
  for (int _____________ = 1; _____________ <= _; _____________++)
    if (___________[_____________][0] == _____________)
      ___________[_____________][0] = 0;
  for (int j = 1; j <= 17; j++)
    for (int _____________ = 1; _____________ <= _; _____________++)
      ___________[_____________][j] =
          ___________[___________[_____________][j - 1]][j - 1];
  int q;
  scanf("%d", &q);
  tot = 0;
  for (int _____________ = 1; _____________ <= q; _____________++) {
    int u, v;
    scanf("%d %d", &u, &v);
    if (u == v) {
      an[_____________] = 0;
      continue;
    }
    if (____________[u] < ____________[v]) swap(u, v);
    int lc = lca(u, v), t = 0;
    if (lc == v) {
      for (int j = 17; j >= 0; j--)
        if (____________[___________[u][j]] > ____________[v])
          u = ___________[u][j], t += 1 << j;
      if (!___________[u][0]) {
        an[_____________] = -1;
        continue;
      }
      an[_____________] = ++t;
      continue;
    }
    for (int j = 17; j >= 0; j--)
      if (____________[___________[u][j]] > ____________[lc])
        u = ___________[u][j], t += 1 << j;
    for (int j = 17; j >= 0; j--)
      if (____________[___________[v][j]] > ____________[lc])
        v = ___________[v][j], t += 1 << j;
    if (!___________[u][0] || !___________[v][0]) {
      an[_____________] = -1;
      continue;
    }
    bz[_____________] = 1;
    an[_____________] = t + 1;
    if (L[u] > L[v]) swap(u, v);
    b[++tot] = (edge){R[u], R[v], _____________, 1};
    b[++tot] = (edge){L[u] - 1, R[v], _____________, -1};
    b[++tot] = (edge){R[u], L[v] - 1, _____________, -1};
    b[++tot] = (edge){L[u] - 1, L[v] - 1, _____________, 1};
  }
  sort(a + 1, a + __ + 1, cmp), sort(b + 1, b + tot + 1, cmp);
  int p = 0;
  for (int _____________ = 1; _____________ <= tot; _____________++) {
    while (p < __ && a[p + 1].x <= b[_____________].x) add(a[++p].y);
    cn[b[_____________].p] += sum(b[_____________].y) * b[_____________].t;
  }
  for (int _____________ = 1; _____________ <= q; _____________++)
    if (bz[_____________]) an[_____________] += cn[_____________] == 0;
  for (int _____________ = 1; _____________ <= q; _____________++)
    printf("%d\n", an[_____________]);
}