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;
inline int read() {
  int x = 0, f = 1, ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
inline void write(int x) {
  if (x < 0) putchar('-'), x = -x;
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(int x) {
  write(x);
  puts("");
}
const int N = 2e5 + 5;
struct edge {
  int link, next;
} e[N << 1];
struct event {
  int x, y, id, opt;
} b[N * 5];
int m, q, n, head[N], tot;
inline void add_edge(int u, int v) {
  e[++tot] = (edge){v, head[u]};
  head[u] = tot;
}
inline void insert(int u, int v) {
  add_edge(u, v);
  add_edge(v, u);
}
int g[N][20], dep[N], fa[N][20], l[N], r[N], cnt;
void dfs(int u, int Fa) {
  dep[u] = dep[Fa] + 1;
  fa[u][0] = Fa;
  l[u] = ++cnt;
  for (int i = 1; i < 20; i++) fa[u][i] = fa[fa[u][i - 1]][i - 1];
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    if (v != Fa) dfs(v, u);
  }
  r[u] = cnt;
}
inline int LCA(int u, int v) {
  if (dep[u] < dep[v]) swap(u, v);
  int delta = dep[u] - dep[v];
  for (int i = 0; i < 20; i++)
    if (delta & (1 << i)) u = fa[u][i];
  for (int i = 19; i >= 0; i--)
    if (fa[u][i] != fa[v][i]) u = fa[u][i], v = fa[v][i];
  if (u != v) return fa[u][0];
  return u;
}
inline void init() {
  n = read();
  for (int i = 2; i <= n; i++) insert(i, read());
  dfs(1, 0);
  m = read();
  tot = 0;
  for (int i = 1; i <= m; i++) {
    int u = read(), v = read(), lca = LCA(u, v);
    if (l[u] > l[v]) swap(u, v);
    if (!g[u][0] || dep[lca] < dep[g[u][0]]) g[u][0] = lca;
    if (!g[v][0] || dep[lca] < dep[g[v][0]]) g[v][0] = lca;
    b[++tot] = (event){l[u], l[v], 0, 1};
  }
}
void Dfs(int u, int Fa) {
  for (int i = head[u]; i; i = e[i].next) {
    int v = e[i].link;
    if (v != Fa) {
      Dfs(v, u);
      if (!g[u][0] || g[v][0] && dep[g[v][0]] < dep[g[u][0]]) g[u][0] = g[v][0];
    }
  }
}
inline bool cmp(event A, event B) {
  return A.x < B.x || (A.x == B.x && A.id < B.id);
}
int bit[N];
inline int lowbit(int x) { return x & (-x); }
inline void update(int x) {
  for (; x <= n; x += lowbit(x)) bit[x]++;
}
inline int query(int x) {
  int sum = 0;
  for (; x; x -= lowbit(x)) sum += bit[x];
  return sum;
}
int ans[N], ANS[N];
inline void solve() {
  Dfs(1, 0);
  for (int i = 1; i <= n; i++)
    if (g[i][0] == i) g[i][0] = 0;
  for (int i = 1; i < 20; i++)
    for (int j = 1; j <= n; j++) g[j][i] = g[g[j][i - 1]][i - 1];
  q = read();
  for (int i = 1; i <= q; i++) {
    int u = read(), v = read(), lca = LCA(u, v);
    if (l[u] > l[v]) swap(u, v);
    for (int j = 19; j >= 0; j--)
      if (g[u][j] && dep[g[u][j]] > dep[lca]) u = g[u][j], ans[i] += (1 << j);
    for (int j = 19; j >= 0; j--)
      if (g[v][j] && dep[g[v][j]] > dep[lca]) v = g[v][j], ans[i] += (1 << j);
    if ((!g[u][0] && u != lca) || (!g[v][0] && v != lca)) {
      ans[i] = -1;
      continue;
    }
    if (u == lca || v == lca)
      ans[i]++;
    else {
      ans[i] += 2;
      b[++tot] = (event){r[u], r[v], i, 1};
      b[++tot] = (event){l[u] - 1, r[v], i, -1};
      b[++tot] = (event){r[u], l[v] - 1, i, -1};
      b[++tot] = (event){l[u] - 1, l[v] - 1, i, 1};
    }
  }
  sort(b + 1, b + 1 + tot, cmp);
  for (int i = 1; i <= tot; i++) {
    if (!b[i].id)
      update(b[i].y);
    else
      ANS[b[i].id] += b[i].opt * query(b[i].y);
  }
  for (int i = 1; i <= q; i++) writeln(ans[i] - (ANS[i] > 0));
}
int main() {
  init();
  solve();
  return 0;
}