#include <bits/stdc++.h>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y <= x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x <= y ? x = y, 1 : 0;
}
const long double eps = 1e-9;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 60;
const int MAXN = 400005;
const int MAXM = 4005;
const int MAXP = 7000000;
const int MX = 200000;
const int G = 3;
const int mods = 1e9 + 7;
const int Gi = (mods + 1) / G;
const int SZ = 62;
const int inv2 = (mods + 1) >> 1;
const int INF = 0x3f3f3f3f;
namespace FastIO {
constexpr int SIZE = (1 << 21) + 1;
int num = 0, f;
char ibuf[SIZE], obuf[SIZE], que[65], *iS, *iT, *oS = obuf,
                                                *oT = obuf + SIZE - 1, c;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char c) {
  *oS++ = c;
  if (oS == oT) flush();
}
inline void getc(char &c) {
  for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c != '.' && c != 'X' && c != EOF;
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
}
inline void reads(char *st) {
  char c;
  int n = 0;
  getc(st[++n]);
  for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c == '.' || c == 'X';
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    st[++n] = c;
  st[++n] = '\0';
}
template <class I>
inline void read(I &x) {
  for (f = 1, c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c >= '0' && c <= '9';
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = (x << 3) + (x << 1) + (c & 15);
  x *= f;
}
template <class I>
inline void print(I x) {
  if (x < 0) putc('-'), x = -x;
  if (!x) putc('0');
  while (x) que[++num] = x % 10 + 48, x /= 10;
  while (num) putc(que[num--]);
}
inline void putstr(string st) {
  for (int i = 0; i < (int)st.size(); ++i) putc(st[i]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_Flusher_;
}  // namespace FastIO
using FastIO ::getc;
using FastIO ::print;
using FastIO ::putc;
using FastIO ::putstr;
using FastIO ::read;
using FastIO ::reads;
pair<long long, long long> C[MAXN];
vector<int> e[MAXN];
struct Qnode {
  int x, l, r, id;
} Q[MAXN];
int Fa[MAXN][20], sz[MAXN], dep[MAXN], fa[MAXN], mx[MAXN], top[MAXN], dfn[MAXN],
    fns[MAXN], Ans[MAXN], tag[MAXN], DFN = 0;
int s[MAXN];
void add(int x, int y) {
  for (; x <= DFN; x += x & (-x)) s[x] += y;
}
int query(int x) {
  int ans = 0;
  for (; x; x -= x & (-x)) ans += s[x];
  return ans;
}
void dfs1(int x, int father) {
  sz[x] = 1, dep[x] = dep[father] + 1, fa[x] = father;
  for (auto v : e[x]) {
    dfs1(v, x);
    sz[x] += sz[v];
    if (sz[v] > sz[mx[x]]) mx[x] = v;
  }
}
void dfs2(int x, int Top) {
  top[x] = Top, dfn[x] = ++DFN;
  if (mx[x]) dfs2(mx[x], Top);
  for (auto v : e[x])
    if (v != mx[x]) dfs2(v, v);
  fns[x] = DFN;
}
int getlca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    u = fa[top[u]];
  }
  return dep[u] > dep[v] ? v : u;
}
void dfs(int x) {
  for (int i = 1; i < 20; ++i) Fa[x][i] = Fa[Fa[x][i - 1]][i - 1];
  for (auto v : e[x]) dfs(v);
}
signed main() {
  int n;
  read(n);
  for (int i = 2, x; i <= n; ++i) read(x), e[x].push_back(i);
  dfs1(1, 0);
  dfs2(1, 1);
  int m, Cnum = 0;
  read(m);
  for (int i = 1; i <= n; ++i) Fa[i][0] = i;
  for (int i = 1, u, v, lca; i <= m; ++i) {
    read(u), read(v), lca = getlca(u, v);
    if (dep[Fa[u][0]] > dep[lca]) Fa[u][0] = lca;
    if (dep[Fa[v][0]] > dep[lca]) Fa[v][0] = lca;
    C[++Cnum] = make_pair(dfn[u], dfn[v]);
    C[++Cnum] = make_pair(dfn[v], dfn[u]);
  }
  sort(C + 1, C + Cnum + 1);
  for (int i = n; i >= 2; --i)
    if (dep[Fa[fa[i]][0]] > dep[Fa[i][0]]) Fa[fa[i]][0] = Fa[i][0];
  dfs(1);
  int M, Qnum = 0;
  read(M);
  for (int i = 1, u, v, lca; i <= M; ++i) {
    read(u), read(v), lca = getlca(u, v);
    for (int j = 19; j >= 0; --j)
      if (Fa[u][j] && dep[Fa[u][j]] > dep[lca]) u = Fa[u][j], Ans[i] += 1 << j;
    for (int j = 19; j >= 0; --j)
      if (Fa[v][j] && dep[Fa[v][j]] > dep[lca]) v = Fa[v][j], Ans[i] += 1 << j;
    if (dep[u] > dep[v]) swap(u, v);
    if (dep[Fa[u][0]] > dep[lca] || dep[Fa[v][0]] > dep[lca])
      Ans[i] = INF;
    else if (dfn[u] <= dfn[v] && dfn[v] <= fns[u])
      --Ans[i];
    else {
      Q[++Qnum] = (Qnode){dfn[u] - 1, dfn[v], fns[v], -i};
      Q[++Qnum] = (Qnode){fns[u], dfn[v], fns[v], i};
    }
  }
  sort(Q + 1, Q + Qnum + 1, [&](Qnode a, Qnode b) { return a.x < b.x; });
  for (int i = 1, nw = 1; i <= Qnum; ++i) {
    while (nw <= Cnum && C[nw].first <= Q[i].x) add(C[nw++].second, 1);
    tag[abs(Q[i].id)] +=
        (query(Q[i].r) - query(Q[i].l - 1)) * (Q[i].id < 0 ? -1 : 1);
  }
  for (int i = 1; i <= M; ++i) {
    if (Ans[i] == INF)
      print(-1);
    else
      print(Ans[i] + 2 - (tag[i] > 0));
    putc('\n');
  }
  return 0;
}

### Prompt

Please provide a CPP coded solution 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>
using namespace std;
template <typename T>
inline bool upmin(T &x, T y) {
  return y <= x ? x = y, 1 : 0;
}
template <typename T>
inline bool upmax(T &x, T y) {
  return x <= y ? x = y, 1 : 0;
}
const long double eps = 1e-9;
const long double pi = acos(-1);
const int oo = 1 << 30;
const long long loo = 1ll << 60;
const int MAXN = 400005;
const int MAXM = 4005;
const int MAXP = 7000000;
const int MX = 200000;
const int G = 3;
const int mods = 1e9 + 7;
const int Gi = (mods + 1) / G;
const int SZ = 62;
const int inv2 = (mods + 1) >> 1;
const int INF = 0x3f3f3f3f;
namespace FastIO {
constexpr int SIZE = (1 << 21) + 1;
int num = 0, f;
char ibuf[SIZE], obuf[SIZE], que[65], *iS, *iT, *oS = obuf,
                                                *oT = obuf + SIZE - 1, c;
inline void flush() {
  fwrite(obuf, 1, oS - obuf, stdout);
  oS = obuf;
}
inline void putc(char c) {
  *oS++ = c;
  if (oS == oT) flush();
}
inline void getc(char &c) {
  for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c != '.' && c != 'X' && c != EOF;
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    ;
}
inline void reads(char *st) {
  char c;
  int n = 0;
  getc(st[++n]);
  for (c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++);
       c == '.' || c == 'X';
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    st[++n] = c;
  st[++n] = '\0';
}
template <class I>
inline void read(I &x) {
  for (f = 1, c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                              (iS == iT ? EOF : *iS++))
                            : *iS++);
       c < '0' || c > '9';
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    if (c == '-') f = -1;
  for (x = 0; c >= '0' && c <= '9';
       c = (iS == iT ? (iT = ((iS = ibuf) + fread(ibuf, 1, SIZE, stdin)),
                       (iS == iT ? EOF : *iS++))
                     : *iS++))
    x = (x << 3) + (x << 1) + (c & 15);
  x *= f;
}
template <class I>
inline void print(I x) {
  if (x < 0) putc('-'), x = -x;
  if (!x) putc('0');
  while (x) que[++num] = x % 10 + 48, x /= 10;
  while (num) putc(que[num--]);
}
inline void putstr(string st) {
  for (int i = 0; i < (int)st.size(); ++i) putc(st[i]);
}
struct Flusher_ {
  ~Flusher_() { flush(); }
} io_Flusher_;
}  // namespace FastIO
using FastIO ::getc;
using FastIO ::print;
using FastIO ::putc;
using FastIO ::putstr;
using FastIO ::read;
using FastIO ::reads;
pair<long long, long long> C[MAXN];
vector<int> e[MAXN];
struct Qnode {
  int x, l, r, id;
} Q[MAXN];
int Fa[MAXN][20], sz[MAXN], dep[MAXN], fa[MAXN], mx[MAXN], top[MAXN], dfn[MAXN],
    fns[MAXN], Ans[MAXN], tag[MAXN], DFN = 0;
int s[MAXN];
void add(int x, int y) {
  for (; x <= DFN; x += x & (-x)) s[x] += y;
}
int query(int x) {
  int ans = 0;
  for (; x; x -= x & (-x)) ans += s[x];
  return ans;
}
void dfs1(int x, int father) {
  sz[x] = 1, dep[x] = dep[father] + 1, fa[x] = father;
  for (auto v : e[x]) {
    dfs1(v, x);
    sz[x] += sz[v];
    if (sz[v] > sz[mx[x]]) mx[x] = v;
  }
}
void dfs2(int x, int Top) {
  top[x] = Top, dfn[x] = ++DFN;
  if (mx[x]) dfs2(mx[x], Top);
  for (auto v : e[x])
    if (v != mx[x]) dfs2(v, v);
  fns[x] = DFN;
}
int getlca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] < dep[top[v]]) swap(u, v);
    u = fa[top[u]];
  }
  return dep[u] > dep[v] ? v : u;
}
void dfs(int x) {
  for (int i = 1; i < 20; ++i) Fa[x][i] = Fa[Fa[x][i - 1]][i - 1];
  for (auto v : e[x]) dfs(v);
}
signed main() {
  int n;
  read(n);
  for (int i = 2, x; i <= n; ++i) read(x), e[x].push_back(i);
  dfs1(1, 0);
  dfs2(1, 1);
  int m, Cnum = 0;
  read(m);
  for (int i = 1; i <= n; ++i) Fa[i][0] = i;
  for (int i = 1, u, v, lca; i <= m; ++i) {
    read(u), read(v), lca = getlca(u, v);
    if (dep[Fa[u][0]] > dep[lca]) Fa[u][0] = lca;
    if (dep[Fa[v][0]] > dep[lca]) Fa[v][0] = lca;
    C[++Cnum] = make_pair(dfn[u], dfn[v]);
    C[++Cnum] = make_pair(dfn[v], dfn[u]);
  }
  sort(C + 1, C + Cnum + 1);
  for (int i = n; i >= 2; --i)
    if (dep[Fa[fa[i]][0]] > dep[Fa[i][0]]) Fa[fa[i]][0] = Fa[i][0];
  dfs(1);
  int M, Qnum = 0;
  read(M);
  for (int i = 1, u, v, lca; i <= M; ++i) {
    read(u), read(v), lca = getlca(u, v);
    for (int j = 19; j >= 0; --j)
      if (Fa[u][j] && dep[Fa[u][j]] > dep[lca]) u = Fa[u][j], Ans[i] += 1 << j;
    for (int j = 19; j >= 0; --j)
      if (Fa[v][j] && dep[Fa[v][j]] > dep[lca]) v = Fa[v][j], Ans[i] += 1 << j;
    if (dep[u] > dep[v]) swap(u, v);
    if (dep[Fa[u][0]] > dep[lca] || dep[Fa[v][0]] > dep[lca])
      Ans[i] = INF;
    else if (dfn[u] <= dfn[v] && dfn[v] <= fns[u])
      --Ans[i];
    else {
      Q[++Qnum] = (Qnode){dfn[u] - 1, dfn[v], fns[v], -i};
      Q[++Qnum] = (Qnode){fns[u], dfn[v], fns[v], i};
    }
  }
  sort(Q + 1, Q + Qnum + 1, [&](Qnode a, Qnode b) { return a.x < b.x; });
  for (int i = 1, nw = 1; i <= Qnum; ++i) {
    while (nw <= Cnum && C[nw].first <= Q[i].x) add(C[nw++].second, 1);
    tag[abs(Q[i].id)] +=
        (query(Q[i].r) - query(Q[i].l - 1)) * (Q[i].id < 0 ? -1 : 1);
  }
  for (int i = 1; i <= M; ++i) {
    if (Ans[i] == INF)
      print(-1);
    else
      print(Ans[i] + 2 - (tag[i] > 0));
    putc('\n');
  }
  return 0;
}

```