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 = 200005;
int n, yl, yr, V, ql, qr, maxbit, fa[20][MAXN], deep[MAXN], clo, dfn[MAXN],
    lst[MAXN], jmp[20][MAXN];
vector<int> G[MAXN], add[MAXN], d[MAXN * 4];
void dfs(int u) {
  dfn[u] = ++clo;
  for (int v : G[u]) {
    deep[v] = deep[u] + 1;
    dfs(v);
  }
  lst[u] = clo;
}
int LCA(int u, int v) {
  if (deep[u] < deep[v]) swap(u, v);
  for (int i = maxbit; i >= 0; i--)
    if (deep[fa[i][u]] >= deep[v]) u = fa[i][u];
  if (u == v) return u;
  for (int i = maxbit; i >= 0; i--)
    if (fa[i][u] != fa[i][v]) {
      u = fa[i][u];
      v = fa[i][v];
    }
  return fa[0][u];
}
void dfs2(int u) {
  int &mx = jmp[0][u];
  mx = u;
  for (int v : add[u])
    if (deep[v] < deep[mx]) mx = v;
  for (int v : G[u]) {
    dfs2(v);
    if (deep[jmp[0][v]] < deep[mx]) mx = jmp[0][v];
  }
}
bool reach(int u, int v) { return deep[jmp[maxbit][u]] <= deep[v]; }
int query(int u, int v) {
  int ret = 1;
  for (int i = maxbit; i >= 0; i--)
    if (deep[jmp[i][u]] > deep[v]) {
      u = jmp[i][u];
      ret += 1 << i;
    }
  return ret;
}
int query(int u, int v, int &p) {
  int ret = 0;
  for (int i = maxbit; i >= 0; i--)
    if (deep[jmp[i][u]] > deep[v]) {
      u = jmp[i][u];
      ret += 1 << i;
    }
  p = u;
  return ret;
}
void update(int o, int l, int r) {
  d[o].push_back(V);
  if (l < r) {
    int m = l + r >> 1;
    if (yl <= m)
      update(o << 1, l, m);
    else
      update(o << 1 | 1, m + 1, r);
  }
}
void build(int o, int l, int r) {
  sort(d[o].begin(), d[o].end());
  d[o].resize(unique(d[o].begin(), d[o].end()) - d[o].begin());
  if (l < r) {
    int m = l + r >> 1;
    build(o << 1, l, m);
    build(o << 1 | 1, m + 1, r);
  }
}
bool query_ok(int o, int l, int r) {
  if (yl <= l && yr >= r) {
    auto k = lower_bound(d[o].begin(), d[o].end(), ql);
    if (k != d[o].end() && *k <= qr) return true;
    return false;
  }
  int m = l + r >> 1;
  if (yl <= m) {
    if (query_ok(o << 1, l, m)) return true;
  }
  if (yr > m) {
    if (query_ok(o << 1 | 1, m + 1, r)) return true;
  }
  return false;
}
bool check(int p1, int p2) {
  yl = dfn[p1];
  yr = lst[p1];
  ql = dfn[p2];
  qr = lst[p2];
  if (query_ok(1, 1, n)) return true;
  return false;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    scanf("%d", &fa[0][i]);
    G[fa[0][i]].push_back(i);
  }
  deep[1] = 1;
  dfs(1);
  while ((1 << maxbit) < n) maxbit++;
  maxbit--;
  for (int j = 1; j <= maxbit; j++)
    for (int i = 1; i <= n; i++) fa[j][i] = fa[j - 1][fa[j - 1][i]];
  int m;
  scanf("%d", &m);
  while (m--) {
    int u, v;
    scanf("%d%d", &u, &v);
    int lca = LCA(u, v);
    yl = dfn[u];
    V = dfn[v];
    update(1, 1, n);
    yl = dfn[v];
    V = dfn[u];
    update(1, 1, n);
    add[u].push_back(lca);
    add[v].push_back(lca);
  }
  build(1, 1, n);
  dfs2(1);
  for (int j = 1; j <= maxbit; j++)
    for (int i = 1; i <= n; i++) jmp[j][i] = jmp[j - 1][jmp[j - 1][i]];
  int q;
  scanf("%d", &q);
  while (q--) {
    int u, v;
    scanf("%d%d", &u, &v);
    int lca = LCA(u, v);
    if (!reach(u, lca) || !reach(v, lca))
      puts("-1");
    else if (u == lca)
      printf("%d\n", query(v, u));
    else if (v == lca)
      printf("%d\n", query(u, v));
    else {
      int p1, p2;
      int d1 = query(u, lca, p1), d2 = query(v, lca, p2);
      int ans = d1 + d2 + 1;
      if (!check(p1, p2)) ans++;
      printf("%d\n", ans);
    }
  }
  return 0;
}