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 int read() {
  int ans = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) ans = (ans << 3) + (ans << 1) + (ch ^ 48), ch = getchar();
  return ans;
}
const int N = 2e5 + 5, inf = 0x3f3f3f3f;
int n, m, fa[N][21], st[N][21], dep[N], bit[N], in[N], out[N], tot = 0, ans[N];
vector<int> e[N], upd[N];
vector<pair<pair<int, int>, int> > q[N];
struct Qry {
  int u, v;
};
inline int ckmin(int a, int b) { return dep[a] < dep[b] ? a : b; }
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int tmp = dep[x] - dep[y];
  for (int i = 20; ~i; --i)
    if ((tmp >> i) & 1) x = fa[x][i];
  if (x == y) return x;
  for (int i = 20; ~i; --i)
    if (fa[x][i] ^ fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void dfs1(int p) {
  in[p] = ++tot;
  for (int i = 1; i <= 20; ++i) fa[p][i] = fa[fa[p][i - 1]][i - 1];
  for (int i = 0; i < e[p].size(); ++i) {
    int v = e[p][i];
    if (v == fa[p][0]) continue;
    dep[v] = dep[p] + 1, dfs1(v);
  }
  out[p] = tot;
}
inline int lowbit(int x) { return x & -x; }
inline void add(int x, int v) {
  for (int i = x; i <= n; i += lowbit(i)) bit[i] += v;
}
inline int query(int x) {
  int ret = 0;
  for (int i = x; i; i -= lowbit(i)) ret += bit[i];
  return ret;
}
void dfs2(int p) {
  for (int i = 0; i < e[p].size(); ++i) {
    int v = e[p][i];
    if (v == fa[p][0]) continue;
    dfs2(v), st[p][0] = ckmin(st[p][0], st[v][0]);
  }
}
inline pair<int, int> find(int s, int t) {
  if (s == t) return pair<int, int>(s, 0);
  if (dep[st[s][20]] > dep[t]) return pair<int, int>(s, -1);
  int ret = 0;
  for (int i = 20; ~i; --i)
    if (dep[st[s][i]] > dep[t]) s = st[s][i], ret |= 1 << i;
  return pair<int, int>(s, ret);
}
inline void dfs3(int p) {
  for (int i = 0; i < q[p].size(); ++i) {
    int pos = q[p][i].first.first;
    q[p][i].first.second = query(out[pos]) - query(in[pos] - 1);
  }
  for (int i = 0; i < upd[p].size(); ++i) {
    int v = upd[p][i];
    add(in[v - p], 1);
  }
  for (int i = 0; i < e[p].size(); ++i) {
    int v = e[p][i];
    if (v == fa[p][0]) continue;
    dfs3(v);
  }
  for (int i = 0; i < q[p].size(); ++i) {
    int pos = q[p][i].first.first;
    if (q[p][i].first.second == query(out[pos]) - query(in[pos] - 1))
      ++ans[q[p][i].second];
  }
}
int main() {
  n = read();
  for (int i = 1; i <= n; ++i) st[i][0] = i;
  for (int i = 2; i <= n; ++i)
    fa[i][0] = read(), e[fa[i][0]].push_back(i), e[i].push_back(fa[i][0]);
  dfs1(1);
  m = read();
  for (int i = 1, u, v, t; i <= m; ++i) {
    u = read(), v = read(), t = lca(u, v), st[u][0] = ckmin(st[u][0], t),
    st[v][0] = ckmin(st[v][0], t);
    upd[u].push_back(u + v), upd[v].push_back(u + v);
  }
  dfs2(1);
  for (int j = 1; j <= 20; ++j)
    for (int i = 1; i <= n; ++i) st[i][j] = st[st[i][j - 1]][j - 1];
  m = read();
  for (int i = 1, u, v, t; i <= m; ++i) {
    u = read(), v = read(), t = lca(u, v);
    pair<int, int> A = find(u, t), B = find(v, t);
    if (A.second == -1 || B.second == -1) {
      ans[i] = -1;
      continue;
    }
    ans[i] = A.second + B.second + 1;
    if (u == t || v == t) continue;
    u = A.first, v = B.first;
    if (in[u] > in[v]) swap(u, v);
    q[u].push_back(make_pair(pair<int, int>(v, 0), i));
  }
  dfs3(1);
  for (int i = 1; i <= m; ++i) printf("%d\n", ans[i]);
  return 0;
}