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;
template <typename T>
void chkmax(T& x, T y) {
  if (x < y) x = y;
}
template <typename T>
void chkmin(T& x, T y) {
  if (x > y) x = y;
}
inline int read() {
  int x = 0;
  char c = getchar();
  bool f = 0;
  while (c < 48) f |= c == '-', c = getchar();
  while (c > 47) x = x * 10 + (c ^ 48), c = getchar();
  return f ? -x : x;
}
const int maxn = 2e5 + 10;
int n, m, q;
vector<int> E[maxn];
int sz[maxn], dfn[maxn], dep[maxn], fa[maxn][18], up[maxn][18];
struct bus {
  int u, v;
} R[maxn];
void cmp(int& x, int y) {
  if (y && (!x || dep[x] > dep[y])) x = y;
}
void dfs(int u) {
  static int now;
  dfn[u] = ++now, dep[u] = dep[fa[u][0]] + 1, sz[u] = 1;
  for (int i = (1), iend = (17); i <= iend; ++i)
    fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int v : E[u]) dfs(v), sz[u] += sz[v];
}
int qlca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = (17), iend = (0); i >= iend; --i)
    if (dep[u] - (1 << i) >= dep[v]) u = fa[u][i];
  if (u == v) return u;
  for (int i = (17), iend = (0); i >= iend; --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
int qkth(int u, int k) {
  for (int i = (17), iend = (0); i >= iend; --i)
    if (k >> i & 1) u = fa[u][i];
  return u;
}
int run(int& u, int anc) {
  int res = 0;
  for (int i = (17), iend = (0); i >= iend; --i) {
    int x = up[u][i];
    if (x && dep[x] > dep[anc]) u = x, res += 1 << i;
  }
  if (!up[u][0] || dep[up[u][0]] > dep[anc]) return -1e9;
  return res;
}
vector<int> fsn[maxn];
int tot, rt[maxn], su[maxn * 40], ls[maxn * 40], rs[maxn * 40];
void ins(int& k, int rt, int l, int r, int x) {
  su[k = ++tot] = su[rt] + 1, ls[k] = ls[rt], rs[k] = rs[rt];
  if (l == r) return;
  int mid = (l + r) / 2;
  x <= mid ? ins(ls[k], ls[rt], l, mid, x) : ins(rs[k], rs[rt], mid + 1, r, x);
}
int query(int k, int l, int r, int ql, int qr) {
  if (ql <= l && r <= qr) return su[k];
  int mid = (l + r) / 2, res = 0;
  if (ql <= mid) res = query(ls[k], l, mid, ql, qr);
  if (qr > mid) res += query(rs[k], mid + 1, r, ql, qr);
  return res;
}
int yysy(int x, int y) { return query(rt[x], 1, n, 1, y); }
bool check(int x1, int x2, int y1, int y2) {
  int res = yysy(x2, y2);
  if (x1 > 1) res -= yysy(x1 - 1, y2);
  if (y1 > 1) res -= yysy(x2, y1 - 1);
  if (x1 > 1 && y1 > 1) res += yysy(x1 - 1, y1 - 1);
  return res > 0;
}
void solve() {
  cin >> n;
  for (int i = (2), iend = (n); i <= iend; ++i)
    E[fa[i][0] = read()].push_back(i);
  dfs(1);
  cin >> m;
  for (int i = (1), iend = (m); i <= iend; ++i) {
    int u = read(), v = read(), anc = qlca(u, v);
    R[i] = {u, v}, cmp(up[u][0], anc), cmp(up[v][0], anc);
    fsn[dfn[u]].push_back(dfn[v]), fsn[dfn[v]].push_back(dfn[u]);
  }
  for (int i = (n), iend = (2); i >= iend; --i) cmp(up[fa[i][0]][0], up[i][0]);
  for (int i = (1), iend = (n); i <= iend; ++i) {
    cmp(up[i][0], i);
    for (int j = (1), jend = (17); j <= jend; ++j)
      up[i][j] = up[up[i][j - 1]][j - 1];
  }
  for (int i = (1), iend = (n); i <= iend; ++i) {
    rt[i] = rt[i - 1];
    for (int x : fsn[i]) ins(rt[i], rt[i], 1, n, x);
  }
  cin >> q;
  while (q--) {
    int u = read(), v = read(), anc = qlca(u, v);
    if (dep[u] < dep[v]) swap(u, v);
    int res = run(u, anc);
    int l = 0, r = dep[v] - dep[anc], nxt = anc;
    while (l <= r) {
      int mid = (l + r) >> 1;
      int ff = qkth(v, mid);
      check(dfn[u], dfn[u] + sz[u] - 1, dfn[ff], dfn[ff] + sz[ff] - 1)
          ? nxt = ff,
            r = mid - 1 : l = mid + 1;
    }
    res += run(v, nxt);
    printf("%d\n", res < 0 ? -1 : res + 1 + (nxt != v));
  }
}
signed main() {
  solve();
  return 0;
}