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 s = 0;
  char ch = getchar();
  while (!isdigit(ch)) ch = getchar();
  while (isdigit(ch)) s = s * 10 + ch - '0', ch = getchar();
  return s;
}
const int N = 2e5 + 5;
int n, m, q;
int f[N][20], g[N][20], dep[N], siz[N], dfn[N], ans[N], c[N], s[N];
int dfn_t;
vector<int> G[N], Q[N], T[N];
vector<tuple<int, int, int> > P[N];
inline void add(int x, int y) {
  for (; x <= n; x += x & -x) c[x] += y;
}
inline int query(int x) {
  int s = 0;
  for (; x; x -= x & -x) s += c[x];
  return s;
}
void dfs1(int u) {
  dfn[u] = ++dfn_t;
  siz[u] = 1;
  dep[u] = dep[f[u][0]] + 1;
  for (int v : G[u]) {
    dfs1(v);
    siz[u] += siz[v];
  }
}
void dfs2(int u) {
  g[u][0] = u;
  for (int i : T[u])
    if (dep[i] < dep[g[u][0]]) g[u][0] = i;
  for (int v : G[u]) {
    dfs2(v);
    if (dep[g[v][0]] < dep[g[u][0]]) g[u][0] = g[v][0];
  }
}
inline int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int i = 19; i >= 0; i--)
    if ((dep[x] - dep[y]) >> i & 1) x = f[x][i];
  if (x == y) return x;
  for (int i = 19; i >= 0; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  return f[x][0];
}
inline pair<int, int> zhuaba(int x, int ff) {
  if (x == ff) return pair<int, int>(x, 0);
  int res = 0;
  for (int i = 19; i >= 0; i--)
    if (dep[g[x][i]] > dep[ff]) x = g[x][i], res += (1 << i);
  if (dep[g[x][0]] <= dep[ff]) return pair<int, int>(x, res);
  return pair<int, int>(x, -1);
}
int main() {
  n = read();
  for (int i = 2; i <= n; i++) {
    f[i][0] = read();
    G[f[i][0]].push_back(i);
  }
  for (int j = 1; j < 20; j++)
    for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];
  dfs1(1);
  m = read();
  for (int i = 1; i <= m; i++) {
    int x = read(), y = read();
    if (x == y) continue;
    if (dfn[x] > dfn[y]) swap(x, y);
    Q[dfn[x]].push_back(dfn[y]);
    int z = lca(x, y);
    if (z != x) T[x].push_back(z);
    if (z != y) T[y].push_back(z);
  }
  dfs2(1);
  for (int j = 1; j < 20; j++)
    for (int i = 1; i <= n; i++) g[i][j] = g[g[i][j - 1]][j - 1];
  q = read();
  for (int i = 1; i <= q; i++) {
    int u = read(), v = read(), x = lca(u, v);
    pair<int, int> a = zhuaba(u, x), b = zhuaba(v, x);
    if (a.second == -1 || b.second == -1) {
      ans[i] = -1;
      continue;
    }
    if (u == x || v == x) {
      ans[i] = a.second + b.second + 1;
      continue;
    }
    ans[i] = a.second + b.second + 2;
    if (dfn[a.first] > dfn[b.first]) swap(a, b);
    P[dfn[a.first] - 1].push_back(tuple<int, int, int>{b.first, i, -1});
    P[dfn[a.first] + siz[a.first] - 1].push_back(
        tuple<int, int, int>{b.first, i, 1});
  }
  for (int i = 1, x, y, z; i <= n; i++) {
    for (int j : Q[i]) add(j, 1);
    for (auto p : P[i]) {
      tie(x, y, z) = p;
      s[y] += z * (query(dfn[x] + siz[x] - 1) - query(dfn[x] - 1));
    }
  }
  for (int i = 1; i <= q; i++) printf("%d\n", ans[i] - (s[i] > 0));
  return 0;
}