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;
inline void File() {}
template <typename T>
inline void read(T &_) {
  _ = 0;
  T __ = getchar(), ___ = 1;
  while (!isdigit(__)) {
    if (__ == '-') ___ = -1;
    __ = getchar();
  }
  while (isdigit(__)) {
    _ = (_ << 1) + (_ << 3) + (__ ^ '0');
    __ = getchar();
  }
  _ *= ___;
}
template <typename T>
inline bool Chkmax(T &_, T __) {
  return _ < __ ? _ = __, 1 : 0;
}
template <typename T>
inline bool Chkmin(T &_, T __) {
  return _ > __ ? _ = __, 1 : 0;
}
const int N = 2e5 + 1e2;
int e, n, m, q, stp, clk, dfs_clk;
int Log[N << 1], St[N << 1][20], Go[N][20], pos[N], dep[N], siz[N];
int beg[N], nex[N << 1], to[N << 1], dfn[N], ans[N];
struct Bus {
  int v, lca;
};
vector<Bus> a[N];
struct Fenwick_Tree {
  int sum[N];
  inline int lowbit(int x) { return x & -x; }
  inline void Add(int x, int val) {
    for (int i = x; i <= n + 10; i += lowbit(i)) sum[i] += val;
  }
  inline int Sum(int x) {
    int res = 0;
    for (int i = x; i; i -= lowbit(i)) res += sum[i];
    return res;
  }
  inline int query(int l, int r) { return Sum(r) - Sum(l - 1); }
} T;
struct ASK {
  int v, id, Ans;
};
vector<ASK> Ans[N];
inline void add(int x, int y) { to[++e] = y, nex[e] = beg[x], beg[x] = e; }
inline int MIN(int x, int y) { return dep[x] < dep[y] ? x : y; }
inline void Dfs1(int x, int ff) {
  dfn[x] = ++dfs_clk;
  siz[x] = 1;
  St[pos[x] = ++clk][0] = x;
  dep[x] = dep[ff] + 1;
  for (int i = beg[x]; i; i = nex[i]) {
    if (to[i] != ff) {
      Dfs1(to[i], x);
      St[++clk][0] = x;
      siz[x] += siz[to[i]];
    }
  }
}
inline void Init() {
  Dfs1(1, 0);
  for (int i = 2; i <= clk; i++) Log[i] = Log[i >> 1] + 1;
  for (int i = 1; (1 << i) <= clk; i++)
    for (int j = 1; j + (1 << i) - 1 <= clk; j++)
      St[j][i] = MIN(St[j][i - 1], St[j + (1 << (i - 1))][i - 1]);
}
inline int LCA(int x, int y) {
  int l = pos[x], r = pos[y];
  if (r < l) swap(l, r);
  int k = Log[r - l + 1];
  return MIN(St[l][k], St[r - (1 << k) + 1][k]);
}
inline int MAX(int x, int y) {
  if (x == 0) return y;
  if (y == 0) return x;
  return dep[x] > dep[y] ? y : x;
}
inline void Dfs2(int x, int ff) {
  for (auto BUS : a[x]) Go[x][0] = MAX(Go[x][0], BUS.lca);
  for (int i = beg[x]; i; i = nex[i]) {
    if (to[i] != ff) {
      Dfs2(to[i], x);
      Go[x][0] = MAX(Go[x][0], Go[to[i]][0]);
    }
  }
  if (Go[x][0] == x) Go[x][0] = 0;
}
inline int Jump(int u, int lca) {
  stp = 0;
  bool flag = 0;
  for (int i = 18; i >= 0; i--) {
    if (dep[Go[u][i]] > dep[lca]) u = Go[u][i], stp += i, flag = 1;
  }
  if (flag) stp = (1 << stp);
  return u;
}
inline void Dfs3(int x, int ff) {
  vector<int> pre;
  for (auto y : Ans[x]) {
    pre.push_back(T.query(dfn[y.v], dfn[y.v] + siz[y.v] - 1));
  }
  for (auto y : a[x]) T.Add(dfn[y.v], 1);
  for (int i = beg[x]; i; i = nex[i]) {
    if (to[i] != ff) {
      Dfs3(to[i], x);
    }
  }
  for (int i = 0, Ed = Ans[x].size(); i < Ed; i++) {
    if (T.query(dfn[Ans[x][i].v], dfn[Ans[x][i].v] + siz[Ans[x][i].v] - 1) !=
        pre[i])
      ans[Ans[x][i].id] = Ans[x][i].Ans + 1;
    else
      ans[Ans[x][i].id] = Ans[x][i].Ans + 2;
  }
}
int main() {
  File();
  read(n);
  for (int p, i = 2; i <= n; i++) read(p), add(p, i), add(i, p);
  Init();
  read(m);
  for (int i = 1, u, v; i <= m; i++) {
    read(u), read(v);
    a[u].push_back((Bus){v, LCA(u, v)});
    a[v].push_back((Bus){u, LCA(v, u)});
  }
  Dfs2(1, 0);
  for (int i = 1; (1 << i) <= n; i++)
    for (int j = 1; j <= n; j++) Go[j][i] = Go[Go[j][i - 1]][i - 1];
  read(q);
  for (int i = 1, u, v; i <= q; i++) {
    read(u), read(v);
    int lu = Jump(u, LCA(u, v)), A = stp;
    int lv = Jump(v, LCA(u, v)), B = stp;
    if (lu == LCA(u, v)) {
      if (Go[lv][0] && dep[Go[lv][0]] <= dep[lu])
        ans[i] = A + B + 1;
      else
        ans[i] = -1;
      continue;
    } else if (lv == LCA(u, v)) {
      if (Go[lu][0] && dep[Go[lu][0]] <= dep[lv])
        ans[i] = A + B + 1;
      else
        ans[i] = -1;
      continue;
    }
    if (!Go[lu][0]) {
      ans[i] = -1;
      continue;
    }
    if (!Go[lv][0]) {
      ans[i] = -1;
      continue;
    }
    Ans[lu].push_back((ASK){lv, i, A + B});
  }
  Dfs3(1, 0);
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i]);
  return 0;
}