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, m, q, ans[maxn], sum[maxn];
struct edge {
  int to, next;
} e[maxn * 2];
int h[maxn], tot;
int Time, fa[maxn], siz[maxn], dep[maxn], son[maxn], dfn[maxn], low[maxn],
    top[maxn];
int f[maxn][20], cnt;
vector<int> route[maxn];
int Sum[maxn];
struct node {
  int Id, x, y1, y2;
  bool operator<(const node &a) const { return x != a.x ? x < a.x : !Id; }
} s[maxn * 5];
inline int gi() {
  char c = getchar();
  while (c < '0' || c > '9') c = getchar();
  int sum = 0;
  while ('0' <= c && c <= '9') sum = sum * 10 + c - 48, c = getchar();
  return sum;
}
inline void add(int u, int v) {
  e[++tot] = (edge){v, h[u]};
  h[u] = tot;
  e[++tot] = (edge){u, h[v]};
  h[v] = tot;
}
void dfs1(int u) {
  siz[u] = 1;
  dfn[u] = ++Time;
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa[u]) {
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs1(v);
      siz[u] += siz[v];
      if (siz[v] > siz[son[u]]) son[u] = v;
    }
  low[u] = Time;
}
void dfs2(int u) {
  if (son[u]) top[son[u]] = top[u], dfs2(son[u]);
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa[u] && v != son[u]) top[v] = v, dfs2(v);
}
inline int get_lca(int u, int v) {
  while (top[u] != top[v]) {
    if (dep[top[u]] > dep[top[v]])
      u = fa[top[u]];
    else
      v = fa[top[v]];
  }
  return dep[u] < dep[v] ? u : v;
}
void dfs3(int u) {
  f[u][0] = u;
  for (int v : route[u]) f[u][0] = dep[v] < dep[f[u][0]] ? v : f[u][0];
  for (int i = h[u], v; v = e[i].to, i; i = e[i].next)
    if (v != fa[u]) {
      dfs3(v);
      f[u][0] = dep[f[v][0]] < dep[f[u][0]] ? f[v][0] : f[u][0];
    }
  if (f[u][0] == u) f[u][0] = 0;
}
void insert(int x, int a) {
  while (x <= n) {
    Sum[x] += a;
    x += x & (-x);
  }
}
int query(int x) {
  int res = 0;
  while (x) {
    res += Sum[x];
    x -= x & (-x);
  }
  return res;
}
int main() {
  n = gi();
  for (int i = 2; i <= n; ++i) add(i, gi());
  dfs1(1);
  top[1] = 1;
  dfs2(1);
  m = gi();
  for (int a, b, lca, i = 1; i <= m; ++i) {
    a = gi();
    b = gi();
    lca = get_lca(a, b);
    route[a].push_back(lca);
    route[b].push_back(lca);
    s[++cnt] = (node){0, dfn[a], 0, dfn[b]};
    s[++cnt] = (node){0, dfn[b], 0, dfn[a]};
  }
  dep[0] = n + 1;
  dfs3(1);
  for (int j = 0; j < 20; ++j)
    for (int i = 1; i <= n; ++i)
      if (f[i][j]) f[i][j + 1] = f[f[i][j]][j];
  q = gi();
  for (int u, v, lca, i = 1; i <= q; ++i) {
    u = gi();
    v = gi();
    lca = get_lca(u, v);
    for (int j = 19; j >= 0; --j)
      if (f[u][j] && dep[f[u][j]] > dep[lca]) u = f[u][j], ans[i] += (1 << j);
    for (int j = 19; j >= 0; --j)
      if (f[v][j] && dep[f[v][j]] > dep[lca]) v = f[v][j], ans[i] += (1 << j);
    if ((!f[u][0] && u != lca) || (!f[v][0] && v != lca)) {
      ans[i] = sum[i] = -1;
      continue;
    }
    if (u == lca || v == lca)
      ++ans[i], sum[i] = -1;
    else
      s[++cnt] = (node){-i, dfn[u] - 1, dfn[v], low[v]},
      s[++cnt] = (node){i, low[u], dfn[v], low[v]};
  }
  stable_sort(s + 1, s + cnt + 1);
  for (int i = 1; i <= cnt; ++i)
    if (!s[i].Id)
      insert(s[i].y2, 1);
    else {
      if (s[i].Id < 0)
        sum[-s[i].Id] -= query(s[i].y2) - query(s[i].y1 - 1);
      else
        sum[s[i].Id] += query(s[i].y2) - query(s[i].y1 - 1);
    }
  for (int i = 1; i <= q; ++i)
    printf("%d\n", ans[i] + (sum[i] < 0 ? 0 : sum[i] > 0 ? 1 : 2));
  return 0;
}