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;
const int N = 500505;
const int mod = 1e9 + 7;
int n, x;
vector<int> g[N];
int jump[N][21];
int up[N][21];
int tin[N], tout[N], timer;
vector<int> a[N];
vector<int> t[4 * N];
inline void dfs(int v, int p = 0) {
  tin[v] = ++timer;
  up[v][0] = p;
  for (int i = 1; i <= 20; ++i) up[v][i] = up[up[v][i - 1]][i - 1];
  for (int to : g[v]) {
    if (to == p) continue;
    dfs(to, v);
  }
  tout[v] = timer;
}
inline int upper(int a, int b) {
  return tin[a] <= tin[b] && tout[b] <= tout[a];
}
inline int get_lca(int a, int b) {
  if (upper(a, b)) return a;
  if (upper(b, a)) return b;
  for (int i = 20; i >= 0; --i)
    if (!upper(up[a][i], b)) a = up[a][i];
  return up[a][0];
}
inline void calc_jump(int v, int p = 0) {
  for (int to : g[v]) {
    if (to == p) continue;
    calc_jump(to, v);
    if (upper(jump[to][0], v)) {
      if (upper(jump[to][0], jump[v][0])) jump[v][0] = jump[to][0];
    }
  }
}
inline void merge(int v, int a, int b) {
  t[v].resize(t[a].size() + t[b].size());
  int i = 0;
  int j = 0;
  while (i < t[a].size() || j < t[b].size()) {
    if (i == t[a].size()) {
      t[v][i + j] = t[b][j++];
    } else if (j == t[b].size()) {
      t[v][i + j] = t[a][i++];
    } else if (t[a][i] < t[b][j]) {
      t[v][i + j] = t[a][i++];
    } else
      t[v][i + j] = t[b][j++];
  }
}
inline void build(int v, int tl, int tr) {
  if (tl == tr) {
    t[v].resize(a[tl].size());
    for (int i = 0; i < a[tl].size(); ++i) t[v][i] = a[tl][i];
    return;
  }
  int tm = (tl + tr) >> 1;
  build(v + v, tl, tm);
  build(v + v + 1, tm + 1, tr);
  merge(v, v + v, v + v + 1);
}
inline int get_cnt(int v, int tl, int tr, int l, int r, int x, int y) {
  if (l > r) return 0;
  if (tl == l && tr == r) {
    return upper_bound(t[v].begin(), t[v].end(), y) -
           lower_bound(t[v].begin(), t[v].end(), x);
  }
  int tm = (tl + tr) >> 1;
  return get_cnt(v + v, tl, tm, l, min(r, tm), x, y) +
         get_cnt(v + v + 1, tm + 1, tr, max(tm + 1, l), r, x, y);
}
inline int get_jump(int a, int b) {
  if (a == b) return 0;
  int ret = 0;
  int ans = 1e9;
  int done = 0;
  for (int j = 20; j >= 0; --j) {
    if (upper(jump[a][j], b))
      ans = min(ans, ret + (1 << j)), done = 1;
    else {
      ret += (1 << j);
      a = jump[a][j];
    }
  }
  if (upper(jump[a][0], b)) ans = min(ans, ret + 1), done = 1;
  if (!done) return 1e9;
  return ans;
}
inline bool can_one(int u, int v) {
  int k1 = get_cnt(1, 1, timer, tin[u], tout[u], tin[v], tout[v]);
  int k2 = get_cnt(1, 1, timer, tin[v], tout[v], tin[u], tout[u]);
  if (!upper(u, v) && !upper(v, u) && (k1 && k2) ||
      upper(u, v) && upper(jump[v][0], u) ||
      upper(v, u) && upper(jump[u][0], v)) {
    return 1;
  }
  return 0;
}
int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  tout[0] = 1e9;
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    cin >> x;
    g[x].push_back(i);
  }
  dfs(1);
  int m;
  cin >> m;
  for (int i = 1; i <= n; ++i) jump[i][0] = i;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    int lca = get_lca(u, v);
    if (upper(lca, jump[u][0])) jump[u][0] = lca;
    if (upper(lca, jump[v][0])) jump[v][0] = lca;
    a[tin[v]].push_back(tin[u]);
    a[tin[u]].push_back(tin[v]);
  }
  calc_jump(1);
  for (int i = 1; i <= timer; ++i) sort(a[i].begin(), a[i].end());
  build(1, 1, timer);
  for (int j = 1; j <= 20; ++j) {
    for (int i = 1; i <= n; ++i) jump[i][j] = jump[jump[i][j - 1]][j - 1];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int u, v;
    cin >> u >> v;
    if (can_one(u, v)) {
      cout << 1 << '\n';
    } else {
      int lca = get_lca(u, v);
      if (!upper(jump[u][20], lca) || !upper(jump[v][20], lca)) {
        cout << -1 << '\n';
        continue;
      }
      int res = 0;
      for (int i = 20; i >= 0; --i) {
        int x = jump[u][i];
        if (!upper(x, v)) res = res + (1 << i), u = x;
      }
      for (int i = 20; i >= 0; --i) {
        int x = jump[v][i];
        if (!upper(x, u)) res = res + (1 << i), v = x;
      }
      res += 1 + !can_one(u, v);
      cout << res << '\n';
    }
  }
  return 0;
}