#include <bits/stdc++.h>
template <typename T>
bool ckmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool ckmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
using namespace std;
const long long inf = 1000000000;
const double Pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
inline int fpow(int a, int b = mod - 2, int p = mod) {
  a %= p;
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % p;
    a = 1ll * a * a % p;
    b >>= 1;
  }
  return res;
}
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    write(-x);
    return;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) {
  write(x);
  putchar('\n');
}
int st[22][1111111], t2, dfn[222222];
int Lg[1111111];
int bg[222222], en[222222], tim;
int fa[222222], dep[222222];
vector<int> e[222222], g[222222];
vector<pair<int, int> > qs[222222];
int n, m, q;
int farw[22][222222];
void dfs1(int u) {
  st[0][++t2] = u;
  dfn[u] = t2;
  bg[u] = ++tim;
  for (int v : e[u])
    if (v ^ fa[u]) {
      dep[v] = dep[u] + 1;
      fa[v] = u;
      dfs1(v);
      st[0][++t2] = u;
    }
  en[u] = tim;
}
inline int get_lp(int x, int y) { return dep[x] < dep[y] ? x : y; }
inline void init_st() {
  for (int i = (2), iE = (t2 + 5); i <= iE; i++) Lg[i] = Lg[i >> 1] + 1;
  for (int i = 1; (1 << i) <= t2; i++) {
    int w = (1 << i);
    for (int j = (1), jE = (t2 - w + 1); j <= jE; j++)
      st[i][j] = get_lp(st[i - 1][j], st[i - 1][j + (w >> 1)]);
  }
}
inline int get_LCA(int x, int y) {
  x = dfn[x], y = dfn[y];
  if (x > y) swap(x, y);
  int i = Lg[y - x + 1], w = (1 << i);
  return get_lp(st[i][x], st[i][y - w + 1]);
}
int val[222222], tag[222222], all, cnt = 1;
int ans[222222];
inline void clr_BIT() {
  ++cnt;
  all = 0;
}
inline void modify_add(int x, int y) {
  if (!x) {
    all += y;
    return;
  }
  for (; x <= n; x += x & -x)
    tag[x] ^ cnt ? tag[x] = cnt, val[x] = 0 : 1, val[x] += y;
}
inline int query_sum(int x) {
  int ret = all;
  for (; x; x = x & (x - 1)) ret += (tag[x] == cnt ? val[x] : 0);
  return ret;
}
inline int query_sum(int l, int r) { return query_sum(r) - query_sum(l - 1); }
void init_farw() {
  for (int i = (n), iE = (1); i >= iE; i--) {
    static int t;
    t = dep[i];
    farw[0][i] = i;
    for (int v : e[i])
      if (ckmin(t, dep[farw[0][v]])) farw[0][i] = farw[0][v];
    for (int v : g[i]) {
      static int l_a;
      l_a = get_LCA(i, v);
      if (ckmin(t, dep[l_a])) farw[0][i] = l_a;
    }
  }
  for (int j = (1), jE = (20); j <= jE; j++)
    for (int i = (1), iE = (n); i <= iE; i++)
      farw[j][i] = farw[j - 1][farw[j - 1][i]];
}
int qr[222222];
void dfs2(int u) {
  for (pair<int, int> v : qs[u])
    qr[v.second] = query_sum(bg[v.first], en[v.first]);
  for (int v : g[u]) modify_add(bg[v], 1);
  for (int v : e[u]) dfs2(v);
  for (pair<int, int> v : qs[u])
    ans[v.second] += (qr[v.second] == query_sum(bg[v.first], en[v.first]));
}
signed main() {
  n = read();
  for (int i = (2), iE = (n); i <= iE; i++) {
    static int x;
    x = read();
    e[x].push_back(i);
  }
  dfs1(1);
  init_st();
  m = read();
  for (int i = (1), iE = (m); i <= iE; i++) {
    static int u, v;
    u = read(), v = read();
    g[u].push_back(v), g[v].push_back(u);
  }
  q = read();
  init_farw();
  for (int i = (1), iE = (q); i <= iE; i++) {
    static int u, v, l_a;
    u = read(), v = read(), l_a = get_LCA(u, v);
    for (int j = (20), jE = (0); j >= jE; j--) {
      if (dep[farw[j][u]] > dep[l_a]) u = farw[j][u], ans[i] += (1 << j);
      if (dep[farw[j][v]] > dep[l_a]) v = farw[j][v], ans[i] += (1 << j);
    }
    if (dep[farw[0][u]] > dep[l_a] || dep[farw[0][v]] > dep[l_a]) {
      ans[i] = -1;
      continue;
    }
    ++ans[i];
    if (u ^ l_a && v ^ l_a) qs[u].push_back(make_pair(v, i));
  }
  dfs2(1);
  for (int i = (1), iE = (q); i <= iE; i++) writeln(ans[i]);
}

### Prompt

Develop a solution in Cpp to the problem described below:

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. 

### Response

```cpp
#include <bits/stdc++.h>
template <typename T>
bool ckmax(T &x, T y) {
  return x < y ? x = y, true : false;
}
template <typename T>
bool ckmin(T &x, T y) {
  return x > y ? x = y, true : false;
}
using namespace std;
const long long inf = 1000000000;
const double Pi = acos(-1);
const int mod = 1e9 + 7;
const double eps = 1e-6;
inline int fpow(int a, int b = mod - 2, int p = mod) {
  a %= p;
  int res = 1;
  while (b) {
    if (b & 1) res = 1ll * res * a % p;
    a = 1ll * a * a % p;
    b >>= 1;
  }
  return res;
}
inline int read() {
  char c = getchar();
  int x = 0;
  bool f = 0;
  for (; !isdigit(c); c = getchar()) f ^= !(c ^ 45);
  for (; isdigit(c); c = getchar()) x = (x << 1) + (x << 3) + (c ^ 48);
  if (f) x = -x;
  return x;
}
inline void write(int x) {
  if (x < 0) {
    putchar('-');
    write(-x);
    return;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writesp(int x) { write(x), putchar(' '); }
inline void writeln(int x) {
  write(x);
  putchar('\n');
}
int st[22][1111111], t2, dfn[222222];
int Lg[1111111];
int bg[222222], en[222222], tim;
int fa[222222], dep[222222];
vector<int> e[222222], g[222222];
vector<pair<int, int> > qs[222222];
int n, m, q;
int farw[22][222222];
void dfs1(int u) {
  st[0][++t2] = u;
  dfn[u] = t2;
  bg[u] = ++tim;
  for (int v : e[u])
    if (v ^ fa[u]) {
      dep[v] = dep[u] + 1;
      fa[v] = u;
      dfs1(v);
      st[0][++t2] = u;
    }
  en[u] = tim;
}
inline int get_lp(int x, int y) { return dep[x] < dep[y] ? x : y; }
inline void init_st() {
  for (int i = (2), iE = (t2 + 5); i <= iE; i++) Lg[i] = Lg[i >> 1] + 1;
  for (int i = 1; (1 << i) <= t2; i++) {
    int w = (1 << i);
    for (int j = (1), jE = (t2 - w + 1); j <= jE; j++)
      st[i][j] = get_lp(st[i - 1][j], st[i - 1][j + (w >> 1)]);
  }
}
inline int get_LCA(int x, int y) {
  x = dfn[x], y = dfn[y];
  if (x > y) swap(x, y);
  int i = Lg[y - x + 1], w = (1 << i);
  return get_lp(st[i][x], st[i][y - w + 1]);
}
int val[222222], tag[222222], all, cnt = 1;
int ans[222222];
inline void clr_BIT() {
  ++cnt;
  all = 0;
}
inline void modify_add(int x, int y) {
  if (!x) {
    all += y;
    return;
  }
  for (; x <= n; x += x & -x)
    tag[x] ^ cnt ? tag[x] = cnt, val[x] = 0 : 1, val[x] += y;
}
inline int query_sum(int x) {
  int ret = all;
  for (; x; x = x & (x - 1)) ret += (tag[x] == cnt ? val[x] : 0);
  return ret;
}
inline int query_sum(int l, int r) { return query_sum(r) - query_sum(l - 1); }
void init_farw() {
  for (int i = (n), iE = (1); i >= iE; i--) {
    static int t;
    t = dep[i];
    farw[0][i] = i;
    for (int v : e[i])
      if (ckmin(t, dep[farw[0][v]])) farw[0][i] = farw[0][v];
    for (int v : g[i]) {
      static int l_a;
      l_a = get_LCA(i, v);
      if (ckmin(t, dep[l_a])) farw[0][i] = l_a;
    }
  }
  for (int j = (1), jE = (20); j <= jE; j++)
    for (int i = (1), iE = (n); i <= iE; i++)
      farw[j][i] = farw[j - 1][farw[j - 1][i]];
}
int qr[222222];
void dfs2(int u) {
  for (pair<int, int> v : qs[u])
    qr[v.second] = query_sum(bg[v.first], en[v.first]);
  for (int v : g[u]) modify_add(bg[v], 1);
  for (int v : e[u]) dfs2(v);
  for (pair<int, int> v : qs[u])
    ans[v.second] += (qr[v.second] == query_sum(bg[v.first], en[v.first]));
}
signed main() {
  n = read();
  for (int i = (2), iE = (n); i <= iE; i++) {
    static int x;
    x = read();
    e[x].push_back(i);
  }
  dfs1(1);
  init_st();
  m = read();
  for (int i = (1), iE = (m); i <= iE; i++) {
    static int u, v;
    u = read(), v = read();
    g[u].push_back(v), g[v].push_back(u);
  }
  q = read();
  init_farw();
  for (int i = (1), iE = (q); i <= iE; i++) {
    static int u, v, l_a;
    u = read(), v = read(), l_a = get_LCA(u, v);
    for (int j = (20), jE = (0); j >= jE; j--) {
      if (dep[farw[j][u]] > dep[l_a]) u = farw[j][u], ans[i] += (1 << j);
      if (dep[farw[j][v]] > dep[l_a]) v = farw[j][v], ans[i] += (1 << j);
    }
    if (dep[farw[0][u]] > dep[l_a] || dep[farw[0][v]] > dep[l_a]) {
      ans[i] = -1;
      continue;
    }
    ++ans[i];
    if (u ^ l_a && v ^ l_a) qs[u].push_back(make_pair(v, i));
  }
  dfs2(1);
  for (int i = (1), iE = (q); i <= iE; i++) writeln(ans[i]);
}

```