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;
namespace io {
const int maxb = 1 << 15;
char b[maxb], *s = b, *t = b;
bool Getchar(char &ch) {
  return ch =
             s == t && (t = (s = b) + fread(b, 1, maxb, stdin)) == b ? 0 : *s++;
}
int Getint() {
  char ch;
  while (Getchar(ch) && (ch < '0' || ch > '9'))
    ;
  int s = ch - '0';
  while (Getchar(ch) && ch >= '0' && ch <= '9') s = s * 10 + ch - '0';
  return s;
}
}  // namespace io
using io::Getint;
const int maxn = 2e5 + 10;
const int inf = 1e8;
vector<int> son[maxn], bus[maxn];
int fa[maxn][20], f[maxn][20], dep[maxn], lowest[maxn];
vector<pair<int, int> > qry[maxn];
bool Chkmin_dep(int &x, const int &y) { return dep[x] > dep[y] ? x = y, 1 : 0; }
int Lca(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int del = dep[u] - dep[v];
  for (int i = 0; del >> i; ++i)
    if (del >> i & 1) u = fa[u][i];
  if (u == v) return u;
  for (int i = 18; ~i; --i)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  return fa[u][0];
}
int Jump(int &u, int v) {
  int res = 0, tmp = u;
  for (int i = 18; ~i; --i)
    if (dep[f[u][i]] > dep[v]) {
      u = f[u][i];
      res += 1 << i;
    }
  return u == tmp ? 0 : res;
}
int n;
int ans[maxn], tree[maxn], tmp[maxn];
int st[maxn], ed[maxn], dfs_clock;
void Update(int x) {
  for (; x <= n; x += x & -x) ++tree[x];
}
int Query(int x) {
  if (!x) return 0;
  int res = 0;
  for (; x; x -= x & -x) res += tree[x];
  return res;
}
void Dfs_init(int u) {
  int deg = son[u].size();
  st[u] = ++dfs_clock;
  for (int i = 0; i < deg; ++i) Dfs_init(son[u][i]);
  ed[u] = dfs_clock;
}
void Dfs(int u) {
  int sizeq = qry[u].size();
  for (int i = 0; i < sizeq; ++i) {
    int v = qry[u][i].first, id = qry[u][i].second;
    tmp[id] = Query(ed[v]) - Query(st[v] - 1);
  }
  int sizeb = bus[u].size();
  for (int i = 0; i < sizeb; ++i) Update(st[bus[u][i]]);
  int deg = son[u].size();
  for (int i = 0; i < deg; ++i) Dfs(son[u][i]);
  for (int i = 0; i < sizeq; ++i) {
    int v = qry[u][i].first, id = qry[u][i].second;
    tmp[id] -= Query(ed[v]) - Query(st[v] - 1);
    if (!tmp[id]) ++ans[id];
  }
}
int main() {
  n = Getint();
  dep[1] = 1;
  for (int i = 2; i <= n; ++i) {
    son[fa[i][0] = Getint()].push_back(i);
    dep[i] = dep[fa[i][0]] + 1;
    for (int j = 0; fa[i][j]; ++j) fa[i][j + 1] = fa[fa[i][j]][j];
  }
  for (int i = 1; i <= n; ++i) f[i][0] = i;
  int m = Getint();
  for (int i = 1; i <= m; ++i) {
    int u = Getint(), v = Getint();
    int lca = Lca(u, v);
    Chkmin_dep(f[u][0], lca);
    Chkmin_dep(f[v][0], lca);
    bus[u].push_back(v);
    bus[v].push_back(u);
  }
  for (int i = n; i > 1; --i) Chkmin_dep(f[fa[i][0]][0], f[i][0]);
  for (int i = 1; i <= n; ++i) {
    for (int j = 0, tmp = f[f[i][j]][j]; tmp && tmp != f[i][j];
         ++j, tmp = f[f[i][j]][j])
      f[i][j + 1] = tmp;
    lowest[i] = i;
    Jump(lowest[i], 0);
  }
  int q = Getint();
  for (int i = 1; i <= q; ++i) {
    int u = Getint(), v = Getint();
    if (u == v) continue;
    int lca = Lca(u, v);
    if (dep[lowest[u]] > dep[lca] || dep[lowest[v]] > dep[lca]) {
      ans[i] = -1;
      continue;
    }
    ans[i] = Jump(u, lca) + Jump(v, lca) + 1;
    if (u == lca || v == lca) continue;
    qry[u].push_back(pair<int, int>(v, i));
  }
  Dfs_init(1);
  Dfs(1);
  for (int i = 1; i <= q; ++i) printf("%d\n", ans[i]);
  return 0;
}