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;
template <class T>
inline void read(T &x) {
  x = 0;
  int f = 0;
  char ch = getchar();
  while (!isdigit(ch)) f = ch == '-', ch = getchar();
  while (isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar();
  x = f ? -x : x;
}
template <class T>
inline void write(T x) {
  if (x < 0) return putchar('-'), write(-x);
  if (x > 9) write(x / 10);
  putchar('0' + x % 10);
}
const int N = 2e5 + 5, MAXN = 1e7 + 5;
struct edge {
  int next, to;
} e[N << 1];
int n, m, Q, fa[N], head[N], dep[N], dfn[N], id[N], tot, cou, rev[N], rfn[N],
    siz[N], f[N][21], g[N][21], rt[N], cnt, tree[MAXN], ls[MAXN], rs[MAXN];
vector<int> num[N];
void add(int u, int v) {
  e[++cnt] = {head[u], v};
  head[u] = cnt;
}
void dfs(int x) {
  dep[x] = dep[f[x][0]] + 1, dfn[x] = ++tot, rev[tot] = x, siz[x] = 1;
  for (int i = 1; i <= 20; i++) f[x][i] = f[f[x][i - 1]][i - 1];
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    dfs(y), siz[x] += siz[y];
  }
  rfn[x] = tot;
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 20; ~i; i--)
    if (dep[f[x][i]] >= dep[y]) x = f[x][i];
  if (x == y) return x;
  for (int i = 20; ~i; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
void DFS1(int x) {
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    DFS1(y);
    if (g[y][0] == x) continue;
    if (dep[g[y][0]] < dep[x] && g[y][0])
      if (!g[x][0] || dep[g[x][0]] > dep[g[y][0]]) g[x][0] = g[y][0];
  }
}
void DFS2(int x) {
  for (int i = 1; i <= 20; i++) g[x][i] = g[g[x][i - 1]][i - 1];
  for (int i = head[x]; i; i = e[i].next) {
    int y = e[i].to;
    DFS2(y);
  }
}
void Add(int l, int r, int pre, int &k, int x) {
  if (!k) k = ++tot;
  if (l == r) return tree[k] = tree[pre] + 1, void();
  tree[k] = tree[pre] + 1;
  if (x <= ((l + r) >> 1))
    rs[k] = rs[pre], Add(l, ((l + r) >> 1), ls[pre], ls[k], x);
  else
    ls[k] = ls[pre], Add(((l + r) >> 1) + 1, r, rs[pre], rs[k], x);
}
int Query(int l, int r, int k1, int k2, int x, int y) {
  if (l >= x && r <= y) return tree[k2] - tree[k1];
  if (x > ((l + r) >> 1))
    return Query(((l + r) >> 1) + 1, r, rs[k1], rs[k2], x, y);
  if (y <= ((l + r) >> 1))
    return Query(l, ((l + r) >> 1), ls[k1], ls[k2], x, y);
  return Query(l, ((l + r) >> 1), ls[k1], ls[k2], x, y) +
         Query(((l + r) >> 1) + 1, r, rs[k1], rs[k2], x, y);
}
int main() {
  read(n);
  for (int i = 2; i <= n; i++) read(f[i][0]), add(f[i][0], i);
  dfs(1);
  read(m);
  for (int i = 1, u, v; i <= m; i++) {
    read(u), read(v);
    int lca = LCA(u, v);
    if ((!g[u][0] || dep[g[u][0]] > dep[lca]) && u != lca) g[u][0] = lca;
    if ((!g[v][0] || dep[g[v][0]] > dep[lca]) && v != lca) g[v][0] = lca;
    if (dfn[u] > dfn[v]) swap(u, v);
    num[dfn[v]].push_back(dfn[u]);
  }
  DFS1(1), DFS2(1);
  for (int i = 1; i <= n; i++) {
    for (int j = 0; j < num[i].size(); j++)
      ++cou, Add(1, n, rt[cou - 1], rt[cou], num[i][j]);
    id[i] = cou;
  }
  read(Q);
  while (Q--) {
    int u, v, res = 0;
    read(u), read(v);
    if (dep[u] > dep[v]) swap(u, v);
    int lca = LCA(u, v);
    if (lca == u) {
      for (int i = 20; ~i; i--)
        if (dep[g[v][i]] > dep[u]) v = g[v][i], res += (1 << i);
      if (!g[v][0])
        puts("-1");
      else
        write(res + 1), puts("");
    } else {
      for (int i = 20; ~i; i--)
        if (dep[g[u][i]] > dep[lca]) u = g[u][i], res += (1 << i);
      for (int i = 20; ~i; i--)
        if (dep[g[v][i]] > dep[lca]) v = g[v][i], res += (1 << i);
      res += 2;
      if (!g[v][0] || !g[u][0]) {
        puts("-1");
        continue;
      }
      if (dfn[u] < dfn[v]) swap(u, v);
      if (Query(1, n, rt[id[dfn[u] - 1]], rt[id[rfn[u]]], dfn[v], rfn[v]))
        res--;
      write(res), puts("");
    }
  }
}