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 maxn = 200001;
const int logn = 20;
struct node {
  int x, y, id, d, type;
  node() {}
  node(int x, int y, int id, int d) : x(x), y(y), id(id), d(d) { type = 0; }
  node(int x, int y) : x(x), y(y) { type = 1; }
  bool operator<(const node &n) const {
    if (x != n.x) return x < n.x;
    return type > n.type;
  }
};
vector<int> adj[maxn];
int reach[maxn][logn];
int anc[maxn][logn];
int prt[maxn];
int cnt[maxn];
int dep[maxn];
int prv[maxn];
vector<node> req[maxn];
int add[maxn];
int f[maxn];
int ans[maxn];
int n, m, q;
void dfs1(int u);
int dfs2(int u);
void dfs3(int u);
void add_query(int u, int l1, int r1, int l2, int r2, int id);
int lca(int u, int v);
void work(int u);
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &prt[i]);
    adj[prt[i]].push_back(i);
  }
  dep[0] = n + 1;
  dep[1] = 1;
  dfs1(1);
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    int l = lca(u, v);
    if (dep[l] < dep[add[u]]) add[u] = l;
    if (dep[l] < dep[add[v]]) add[v] = l;
    if (prv[u] > prv[v]) swap(u, v);
    req[l].push_back(node(prv[u], prv[v]));
  }
  dfs2(1);
  dfs3(1);
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    if (dep[u] > dep[v]) swap(u, v);
    int l = lca(u, v);
    int cu = u;
    int cv = v;
    int cur_ans = 0;
    for (int j = logn - 1; j >= 0; j--) {
      if (reach[cu][j] && dep[reach[cu][j]] > dep[l]) {
        cu = reach[cu][j];
        cur_ans += (1 << j);
      }
      if (reach[cv][j] && dep[reach[cv][j]] > dep[l]) {
        cv = reach[cv][j];
        cur_ans += (1 << j);
      }
    }
    if (u == l) {
      if (dep[reach[cv][0]] > dep[l]) {
        ans[i] = -1;
      } else {
        ans[i] = cur_ans + 1;
      }
    } else if (dep[reach[cu][0]] > dep[l] || dep[reach[cv][0]] > dep[l]) {
      ans[i] = -1;
    } else {
      ans[i] = cur_ans + 2;
      add_query(l, prv[cu], prv[cu] + cnt[cu] - 1, prv[cv],
                prv[cv] + cnt[cv] - 1, i);
    }
  }
  for (int i = 1; i <= n; i++) {
    work(i);
  }
  for (int i = 1; i <= q; i++) {
    if (f[i] > 0) ans[i]--;
    printf("%d\n", ans[i]);
  }
  return 0;
}
void dfs1(int u) {
  static int t = 0;
  prv[u] = ++t;
  for (int i = 1; i < logn; i++) {
    anc[u][i] = anc[anc[u][i - 1]][i - 1];
  }
  cnt[u] = 1;
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == anc[u][0]) continue;
    anc[v][0] = u;
    dep[v] = dep[u] + 1;
    dfs1(v);
    cnt[u] += cnt[v];
  }
}
int dfs2(int u) {
  int r = add[u];
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == anc[u][0]) continue;
    int cur = dfs2(v);
    if (dep[cur] < dep[r]) r = cur;
  }
  if (u == r) r = 0;
  reach[u][0] = r;
  return r;
}
void dfs3(int u) {
  for (int i = 1; i < logn; i++) {
    reach[u][i] = reach[reach[u][i - 1]][i - 1];
  }
  for (int i = 0; i < adj[u].size(); i++) {
    int v = adj[u][i];
    if (v == anc[u][0]) continue;
    dfs3(v);
  }
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  for (int i = logn - 1; i >= 0; i--) {
    if (dep[u] - (1 << i) >= dep[v]) u = anc[u][i];
  }
  if (u == v) return u;
  for (int i = logn - 1; i >= 0; i--) {
    if (anc[u][i] != anc[v][i]) {
      u = anc[u][i];
      v = anc[v][i];
    }
  }
  return anc[u][0];
}
void add_query(int u, int l1, int r1, int l2, int r2, int id) {
  if (l1 > l2) {
    swap(l1, l2);
    swap(r1, r2);
  }
  req[u].push_back(node(r1, r2, id, 1));
  req[u].push_back(node(r1, l2 - 1, id, -1));
  req[u].push_back(node(l1 - 1, r2, id, -1));
  req[u].push_back(node(l1 - 1, l2 - 1, id, 1));
}
int b[maxn];
void change(int x, int d);
int query(int x);
void work(int u) {
  sort(req[u].begin(), req[u].end());
  for (int i = 0; i < req[u].size(); i++) {
    if (req[u][i].type == 1) {
      change(req[u][i].y, 1);
    } else {
      f[req[u][i].id] += req[u][i].d * query(req[u][i].y);
    }
  }
  for (int i = 0; i < req[u].size(); i++) {
    if (req[u][i].type == 1) {
      change(req[u][i].y, -1);
    }
  }
}
int low_bit(int x) { return x & -x; }
void change(int x, int d) {
  for (int i = x; i <= n; i += low_bit(i)) {
    b[i] += d;
  }
}
int query(int x) {
  int ans = 0;
  for (int i = x; i >= 1; i -= low_bit(i)) {
    ans += b[i];
  }
  return ans;
}