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;
using ll = long long;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
struct ancestor {
  vector<int> vin, vout, d;
  vector<vector<int>> adj, p;
  int n, t = 0, e;
  void dfs(int i, int v) {
    vin[i] = t++;
    p[i][0] = v, d[i] = d[v] + 1;
    for (int j = 1; j <= e; j++) p[i][j] = p[p[i][j - 1]][j - 1];
    for (auto& j : adj[i])
      if (j != v) dfs(j, i);
    vout[i] = t - 1;
  }
  ancestor(vector<vector<int>> _adj = {}, int root = 0)
      : adj(_adj), n(_adj.size()) {
    if (adj.empty()) return;
    vin.resize(n), vout.resize(n), d.assign(n, 0);
    e = ceil(log2(n));
    p.assign(n, vector<int>(e + 1));
    dfs(root, root);
  }
  bool is_ancestor(int i, int j) const {
    return vin[i] <= vin[j] && vout[i] >= vout[j];
  }
  int ktha(int i, int k) const {
    for (int j = 0; (1 << j) <= k; j++)
      if (k & (1 << j)) i = p[i][j];
    return i;
  }
  int lca(int i, int j) const {
    if (is_ancestor(i, j)) return i;
    if (is_ancestor(j, i)) return j;
    for (int k = e; k >= 0; k--)
      if (!is_ancestor(p[i][k], j)) i = p[i][k];
    return p[i][0];
  }
  int step(int i, int j) const {
    return is_ancestor(i, j) ? ktha(j, d[j] - d[i] - 1) : p[i][0];
  }
  int dist(int i, int j) { return d[i] + d[j] - 2 * d[lca(i, j)]; }
};
struct segtree {
  using node = vector<int>;
  vector<int> a, b;
  vector<node> tree;
  int n;
  segtree(vector<vector<int>>& v) {
    n = 1 << int(ceil(log2(v.size())));
    tree.resize(2 * n);
    a.resize(2 * n);
    b.resize(2 * n);
    for (int i = 2 * n - 1; i > 0; i--) {
      if (i >= n) {
        a[i] = b[i] = i - n;
        if (i - n < v.size()) {
          tree[i] = v[i - n];
          sort((tree[i]).begin(), (tree[i]).end());
        }
      } else {
        a[i] = a[2 * i];
        b[i] = b[2 * i + 1];
        merge((tree[2 * i]).begin(), (tree[2 * i]).end(),
              (tree[2 * i + 1]).begin(), (tree[2 * i + 1]).end(),
              back_inserter(tree[i]));
      }
    }
  }
  bool get(int i, int x, int y) {
    return lower_bound((tree[i]).begin(), (tree[i]).end(), x) !=
           upper_bound((tree[i]).begin(), (tree[i]).end(), y);
  }
  bool query(int l, int r, int x, int y, int i = 1) {
    if (l <= a[i] && r >= b[i]) return get(i, x, y);
    if (l > b[i] || r < a[i]) return 0;
    return query(l, r, x, y, 2 * i) || query(l, r, x, y, 2 * i + 1);
  }
};
const int N = 2e5 + 5, K = 20;
int jump[N], ans[N];
array<int, 2> qry[N];
vector<vector<int>> adj, j_adj;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int n;
  cin >> n;
  adj.resize(n);
  j_adj.resize(n + 1);
  for (int i = 1; i < n; i++) {
    int x;
    cin >> x;
    adj[x - 1].push_back(i);
  }
  iota(jump, jump + n, 0);
  ancestor anc(adj, 0);
  vector<vector<int>> buses(n + 1);
  int m;
  cin >> m;
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    int z = anc.lca(x, y);
    if (anc.d[z] < anc.d[jump[x]]) jump[x] = z;
    if (anc.d[z] < anc.d[jump[y]]) jump[y] = z;
    if (anc.vin[x] > anc.vin[y]) swap(x, y);
    0;
    buses[anc.vin[x]].push_back(anc.vin[y]);
  }
  segtree seg(buses);
  for (int i = n - 1; i >= 0; i--)
    for (int j : adj[i])
      if (anc.d[jump[j]] < anc.d[jump[i]]) jump[i] = jump[j];
  for (int i = 0; i < n; i++) {
    if (jump[i] == i)
      j_adj[n].push_back(i);
    else
      j_adj[jump[i]].push_back(i);
  }
  0;
  0;
  ancestor j_anc(j_adj, n);
  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    if (anc.vin[x] > anc.vin[y]) swap(x, y);
    if (j_anc.lca(x, y) == n)
      ans[i] = -1;
    else if (anc.is_ancestor(x, y)) {
      for (int k = j_anc.e; k >= 0; k--)
        if (j_anc.p[y][k] != n && !anc.is_ancestor(j_anc.p[y][k], x))
          y = j_anc.p[y][k], ans[i] += 1 << k;
      ans[i]++;
    } else {
      for (int k = j_anc.e; k >= 0; k--)
        if (j_anc.p[y][k] != n && !anc.is_ancestor(j_anc.p[y][k], x))
          y = j_anc.p[y][k], ans[i] += 1 << k;
      for (int k = j_anc.e; k >= 0; k--)
        if (j_anc.p[x][k] != n && !anc.is_ancestor(j_anc.p[x][k], y))
          x = j_anc.p[x][k], ans[i] += 1 << k;
      ans[i] += 2;
      if (seg.query(anc.vin[x], anc.vout[x], anc.vin[y], anc.vout[y])) ans[i]--;
    }
  }
  for (int i = 0; i < q; i++) cout << ans[i] << "\n";
}