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;
  char c = getchar();
  int f = 1;
  while (!isdigit(c)) {
    if (c == '-') f = -1;
    c = getchar();
  }
  while (isdigit(c)) x = x * 10 - '0' + c, c = getchar();
  x *= f;
}
const int N = 2e5 + 10;
int d[N][19], p[N][19], dep[N], dfn[N], sz[N], n, m, id;
vector<int> G[N], U[N];
void dfs1(int u, int last) {
  dfn[u] = ++id, sz[u] = 1;
  p[u][0] = last, dep[u] = dep[last] + 1;
  for (int j = 1; j <= 18; ++j) p[u][j] = p[p[u][j - 1]][j - 1];
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v == last) continue;
    dfs1(v, u);
    sz[u] += sz[v];
  }
}
void dfs2(int u, int last) {
  d[u][0] = u;
  for (int i = 0; i < G[u].size(); ++i) {
    int v = G[u][i];
    if (v == last) continue;
    dfs2(v, u);
    if (dep[d[v][0]] < dep[d[u][0]]) d[u][0] = d[v][0];
  }
  for (int j = 0; j < U[u].size(); ++j)
    if (dep[d[u][0]] > dep[U[u][j]]) d[u][0] = U[u][j];
}
int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int j = 18; j >= 0; --j)
    if (dep[x] - (1 << j) >= dep[y]) x = p[x][j];
  if (x == y) return x;
  for (int j = 18; j >= 0; --j)
    if (p[x][j] != p[y][j]) x = p[x][j], y = p[y][j];
  return p[x][0];
}
int Up(int &x, int f) {
  if (x == f) return -1;
  int ans = 0;
  for (int j = 18; j >= 0; --j)
    if (dep[d[x][j]] > dep[f]) x = d[x][j], ans += (1 << j);
  return ans;
}
int Ans[N], ex[N];
struct Que {
  int x, y;
} Q[N];
struct itm {
  int id, l, r, t;
};
vector<itm> ss[N];
vector<int> UPD[N];
struct BIT {
  int c[N];
  void add(int i, int t) {
    for (; i <= n; i += i & -i) c[i] += t;
  }
  int query(int i) {
    int ans = 0;
    for (; i; i -= i & -i) ans += c[i];
    return ans;
  }
} BT;
void work() {
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j < UPD[i].size(); ++j) BT.add(UPD[i][j], 1);
    for (int j = 0; j < ss[i].size(); ++j)
      ex[ss[i][j].id] +=
          ss[i][j].t * (BT.query(ss[i][j].r) - BT.query(ss[i][j].l - 1));
  }
}
int main() {
  int x, y, q;
  read(n);
  for (int i = 2; i <= n; ++i) read(x), G[x].push_back(i);
  dfs1(1, 0);
  read(m);
  for (int i = 1; i <= m; ++i) {
    read(Q[i].x), read(Q[i].y);
    int L = LCA(Q[i].x, Q[i].y);
    U[Q[i].x].push_back(L), U[Q[i].y].push_back(L);
    if (dfn[Q[i].x] < dfn[Q[i].y])
      UPD[dfn[Q[i].x]].push_back(dfn[Q[i].y]);
    else
      UPD[dfn[Q[i].y]].push_back(dfn[Q[i].x]);
  }
  dfs2(1, 0);
  for (int j = 1; j <= 18; ++j)
    for (int i = 1; i <= n; ++i) d[i][j] = d[d[i][j - 1]][j - 1];
  read(q);
  for (int cur = 1; cur <= q; ++cur) {
    read(x), read(y);
    if (x == y) {
      Ans[cur] = 0;
      continue;
    }
    if (dep[x] < dep[y]) swap(x, y);
    int L = LCA(x, y);
    if (L == y) {
      if (dep[d[x][18]] > dep[y])
        Ans[cur] = -1;
      else
        Ans[cur] = Up(x, y) + 1;
      continue;
    }
    if (dep[d[x][18]] > dep[L] || dep[d[y][18]] > dep[L]) {
      Ans[cur] = -1;
      continue;
    }
    int fx = x, fy = y;
    Ans[cur] = Up(fx, L) + Up(fy, L) + 2;
    if (dfn[fx] > dfn[fy]) swap(fx, fy);
    ss[dfn[fx] - 1].push_back((itm){cur, dfn[fy], dfn[fy] + sz[fy] - 1, -1});
    ss[dfn[fx] + sz[fx] - 1].push_back(
        (itm){cur, dfn[fy], dfn[fy] + sz[fy] - 1, 1});
  }
  work();
  for (int i = 1; i <= q; ++i) {
    if (Ans[i] != -1 && ex[i]) Ans[i]--;
    printf("%d\n", Ans[i]);
  }
  return 0;
}