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 INF = 1E9 + 77;
const int maxn = 2E5 + 77;
const int log2maxn = 19;
struct EDGE {
  int to, next;
} edges[maxn];
int cEdge = 1, head[maxn];
void addEdge(int from, int to) {
  edges[cEdge] = (EDGE){to, head[from]};
  head[from] = cEdge++;
}
int N, M, Q, H[maxn], P[maxn][log2maxn], ans[maxn], A[maxn], B[maxn], L[maxn],
    D[maxn], PD[maxn][log2maxn];
vector<pair<int, pair<int, int>>> V[maxn];
vector<int> VM[maxn];
int lca(int a, int b) {
  if (H[a] < H[b]) swap(a, b);
  for (int i = log2maxn - 1; i >= 0; --i)
    if (H[P[a][i]] >= H[b]) a = P[a][i];
  if (a == b) return a;
  for (int i = log2maxn - 1; i >= 0; --i)
    if (P[a][i] != P[b][i]) a = P[a][i], b = P[b][i];
  return P[a][0];
}
int minDis(int u, int l) {
  int ret = 0;
  for (int i = log2maxn - 1; i >= 0; --i) {
    if (H[PD[u][i]] > H[l]) {
      ret += 1 << i;
      u = PD[u][i];
    }
  }
  if (H[PD[u][0]] <= H[l])
    return ret + 1;
  else
    return INF;
}
int upDis(int u, int d) {
  for (int i = log2maxn - 1; i >= 0; --i) {
    int c = 1 << i;
    if (c <= d) {
      u = PD[u][i];
      d -= c;
    }
  }
  return u;
}
int pre[maxn], suf[maxn], cidx = 0;
void dfs1(int u) {
  pre[u] = ++cidx;
  for (int k = head[u]; k; k = edges[k].next) {
    int v = edges[k].to;
    dfs1(v);
  }
  suf[u] = cidx;
}
int C[maxn];
int sum(int p) {
  int ret = 0;
  for (; p; p -= p & -p) ret += C[p];
  return ret;
}
int sum(int l, int r) { return sum(r) - sum(l - 1); }
void add(int p) {
  for (; p < maxn; p += p & -p) C[p]++;
}
void dfs2(int u) {
  for (vector<pair<int, pair<int, int>>>::iterator it = V[u].begin();
       it != V[u].end(); ++it) {
    int v = it->first;
    it->second.second = sum(pre[v], suf[v]);
  }
  for (vector<int>::iterator it = VM[u].begin(); it != VM[u].end(); ++it) {
    add(pre[*it]);
  }
  for (int k = head[u]; k; k = edges[k].next) {
    int v = edges[k].to;
    dfs2(v);
  }
  for (vector<pair<int, pair<int, int>>>::iterator it = V[u].begin();
       it != V[u].end(); ++it) {
    int v = it->first, t = sum(pre[v], suf[v]);
    if (t != it->second.second) {
      ans[it->second.first]--;
    }
  }
}
int main() {
  scanf("%d", &N);
  H[1] = 1;
  D[1] = 1;
  for (int i = 2; i <= N; ++i) {
    D[i] = i;
    int p;
    scanf("%d", &p);
    addEdge(p, i);
    H[i] = H[p] + 1;
    P[i][0] = p;
    for (int j = 1; j < log2maxn; ++j) P[i][j] = P[P[i][j - 1]][j - 1];
  }
  scanf("%d", &M);
  for (int i = 1; i <= M; ++i) {
    scanf("%d%d", A + i, B + i);
    L[i] = lca(A[i], B[i]);
    if (H[L[i]] < H[D[A[i]]]) D[A[i]] = L[i];
    if (H[L[i]] < H[D[B[i]]]) D[B[i]] = L[i];
    VM[A[i]].push_back(B[i]);
    VM[B[i]].push_back(A[i]);
  }
  for (int i = N; i > 1; --i) {
    if (H[D[i]] < H[D[P[i][0]]]) D[P[i][0]] = D[i];
  }
  for (int i = 1; i <= N; ++i) {
    PD[i][0] = D[i];
    for (int j = 1; j < log2maxn; ++j) PD[i][j] = PD[PD[i][j - 1]][j - 1];
  }
  scanf("%d", &Q);
  for (int i = 1; i <= Q; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    int l = lca(u, v);
    if (H[u] < H[v]) swap(u, v);
    int du = minDis(u, l);
    ans[i] = du;
    if (l == v) {
      continue;
    }
    int dv = minDis(v, l);
    ans[i] += dv;
    int ppu = upDis(u, du - 1), ppv = upDis(v, dv - 1);
    V[ppu].push_back(make_pair(ppv, make_pair(i, 0)));
  }
  dfs1(1);
  dfs2(1);
  for (int i = 1; i <= Q; ++i) {
    if (ans[i] < INF)
      printf("%d\n", ans[i]);
    else
      printf("-1\n");
  }
}