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;
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
const int maxn = 2e5 + 10, maxm = 3e5 + 10, lg = 21, mod = 1e9 + 7, inf = 1e18;
int n, m, q, par[maxn][lg + 1], bus[maxn][lg + 1], A[maxn], B[maxn], h[maxn],
    st[maxn], ft[maxn], tt, mn[maxn];
vector<int> g[maxn], bb[maxn];
void pfs(int v = 1, int p = 0) {
  st[v] = tt++;
  par[v][0] = p;
  for (int i = 1; i <= lg; i++) par[v][i] = par[par[v][i - 1]][i - 1];
  h[v] = h[p] + 1;
  for (auto u : g[v])
    if (u != p) pfs(u, v);
  ft[v] = tt;
}
int lca(int v, int u) {
  if (h[v] < h[u]) swap(v, u);
  for (int i = 0, x = h[v] - h[u]; i <= lg; i++)
    if (x >> i & 1) v = par[v][i];
  if (v == u) return v;
  for (int i = lg; i >= 0; i--)
    if (par[v][i] != par[u][i]) v = par[v][i], u = par[u][i];
  return par[v][0];
}
void pff(int v = 1, int p = 0) {
  mn[v] = v;
  for (auto i : bb[v]) {
    int u = lca(v, A[i] ^ B[i] ^ v);
    if (h[u] < h[mn[v]]) mn[v] = u;
  }
  for (auto u : g[v])
    if (u != p) {
      pff(u, v);
      if (h[mn[u]] < h[mn[v]]) mn[v] = mn[u];
    }
}
void dfs(int v = 1, int p = 0) {
  bus[v][0] = mn[v];
  for (int i = 1; i <= lg; i++) bus[v][i] = bus[bus[v][i - 1]][i - 1];
  for (auto u : g[v])
    if (u != p) dfs(u, v);
}
vector<pair<int, int> > seg[maxn << 2];
void add(int i, pair<int, int> p, int s = 0, int t = n, int v = 1) {
  seg[v].push_back(p);
  if (t - s == 1) return;
  (i < ((s + t) >> 1) ? add(i, p, s, ((s + t) >> 1), (v << 1))
                      : add(i, p, ((s + t) >> 1), t, ((v << 1) ^ 1)));
}
bool get(int l, int r, int l2, int r2, int s = 0, int t = n, int v = 1) {
  if (l >= t || r <= s) return 0;
  if (l <= s && r >= t) {
    auto lb = lower_bound(seg[v].begin(), seg[v].end(), make_pair(l2, 0));
    if (lb == seg[v].end()) return 0;
    return ((lb->second) <= r2);
  }
  return get(l, r, l2, r2, s, ((s + t) >> 1), (v << 1)) |
         get(l, r, l2, r2, ((s + t) >> 1), t, ((v << 1) ^ 1));
}
pair<int, int> bet(int v, int u) {
  if (h[bus[v][lg]] > h[u]) return {-1, -1};
  int ret = 0;
  for (int i = lg; i >= 0; i--)
    if (h[bus[v][i]] > h[u]) v = bus[v][i], ret += (1 << i);
  return {ret + 1, v};
}
int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    g[p].push_back(i);
  }
  pfs();
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> A[i] >> B[i];
    bb[A[i]].push_back(i), bb[B[i]].push_back(i);
    add(st[A[i]], make_pair(st[B[i]], ft[B[i]]));
    add(st[B[i]], make_pair(st[A[i]], ft[A[i]]));
  }
  for (int i = 0; i < 4 * maxn; i++) {
    sort(seg[i].begin(), seg[i].end());
    for (int j = (int)(seg[i].size()) - 1, nw = mod; j >= 0; j--) {
      nw = min(nw, seg[i][j].second);
      seg[i][j].second = nw;
    }
  }
  pff(), dfs();
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int v, u;
    cin >> v >> u;
    int w = lca(v, u);
    if (w == v) {
      cout << bet(u, v).first << '\n';
      continue;
    }
    if (w == u) {
      cout << bet(v, u).first << '\n';
      continue;
    }
    pair<int, int> a = bet(u, w), b = bet(v, w);
    if (a.first == -1 || b.first == -1) {
      cout << "-1\n";
      continue;
    }
    cout << a.first + b.first -
                get(st[a.second], ft[a.second], st[b.second], ft[b.second])
         << '\n';
  }
  return 0;
}