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>
#pragma comment(linker, "/STACK:16000000")
using namespace std;
const int Maxn = 200005;
const int Maxs = 1048576;
const int Maxm = 20;
int n;
vector<int> neigh[Maxn];
int L[Maxn], P[Maxn][Maxm];
int my[Maxn];
int cur, lef[Maxn], rig[Maxn];
int m;
vector<int> st[Maxs];
vector<pair<int, int> > rl;
map<pair<int, int>, map<int, int> > M;
int q;
void Add(int v, int l, int r, int x, int val) {
  st[v].push_back(val);
  if (l < r) {
    int m = l + r >> 1;
    if (x <= m)
      Add(2 * v, l, m, x, val);
    else
      Add(2 * v + 1, m + 1, r, x, val);
  }
}
bool Get(int v, int l, int r, int a, int b, int val1, int val2) {
  if (l == a && r == b) {
    int ind = lower_bound(st[v].begin(), st[v].end(), val1) - st[v].begin();
    return ind < st[v].size() && st[v][ind] <= val2;
  } else {
    int m = l + r >> 1;
    bool res = false;
    if (a <= m) res |= Get(2 * v, l, m, a, min(m, b), val1, val2);
    if (m + 1 <= b)
      res |= Get(2 * v + 1, m + 1, r, max(m + 1, a), b, val1, val2);
    return res;
  }
}
int getLCA(int a, int b) {
  if (L[a] < L[b]) swap(a, b);
  for (int i = Maxm - 1; i >= 0; i--)
    if (L[a] - (1 << i) >= L[b]) a = P[a][i];
  if (a == b) return a;
  for (int i = Maxm - 1; i >= 0; i--)
    if (P[a][i] != P[b][i]) a = P[a][i], b = P[b][i];
  return P[a][0];
}
void Insert(map<int, int> &M, int x, int val) {
  map<int, int>::iterator it = M.lower_bound(x);
  if (it != M.end() && val <= it->second) return;
  it = M.upper_bound(x);
  while (it != M.begin()) {
    it--;
    if (it->second <= val)
      M.erase(it++);
    else
      break;
  }
  M.insert(make_pair(x, val));
}
bool Get(map<int, int> &M, int x, int val) {
  map<int, int>::iterator it = M.lower_bound(x);
  return it != M.end() && val <= it->second;
}
void Enumerate(int v) {
  lef[v] = ++cur;
  for (int i = 0; i < neigh[v].size(); i++) Enumerate(neigh[v][i]);
  rig[v] = cur;
}
void Traverse(int v) {
  for (int i = 0; i < neigh[v].size(); i++) {
    int u = neigh[v][i];
    Traverse(u);
    my[v] = min(my[v], my[u]);
  }
}
int Solve(int a, int b) {
  if (L[a] < L[b]) swap(a, b);
  int lca = getLCA(a, b);
  if (b == lca) {
    int cnt = 0;
    while (L[a] > L[b]) {
      if (my[a] == a) return -1;
      cnt++;
      a = my[a];
    }
    return cnt;
  }
  int res = 0;
  while (true) {
    if (my[a] == a) return -1;
    if (L[my[a]] <= L[lca]) break;
    res++;
    a = my[a];
  }
  while (true) {
    if (my[b] == b) return -1;
    if (L[my[b]] <= L[lca]) break;
    res++;
    b = my[b];
  }
  if (lef[a] > lef[b]) swap(a, b);
  if (Get(1, 1, n, lef[a], rig[a], lef[b], rig[b]))
    res++;
  else
    res += 2;
  return res;
}
int main() {
  scanf("%d", &n);
  for (int i = 2; i <= n; i++) {
    int p;
    scanf("%d", &p);
    neigh[p].push_back(i);
    L[i] = L[p] + 1;
    P[i][0] = p;
  }
  for (int j = 1; j < Maxm; j++)
    for (int i = 1; i <= n; i++) P[i][j] = P[P[i][j - 1]][j - 1];
  for (int i = 1; i <= n; i++) my[i] = i;
  Enumerate(1);
  scanf("%d", &m);
  while (m--) {
    int a, b;
    scanf("%d %d", &a, &b);
    int lca = getLCA(a, b);
    my[a] = min(my[a], lca);
    my[b] = min(my[b], lca);
    if (lef[a] > lef[b]) swap(a, b);
    rl.push_back(pair<int, int>(lef[b], lef[a]));
  }
  sort(rl.begin(), rl.end());
  for (int i = 0; i < rl.size(); i++) {
    int l = rl[i].second, r = rl[i].first;
    Add(1, 1, n, l, r);
  }
  Traverse(1);
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d %d", &a, &b);
    printf("%d\n", Solve(a, b));
  }
  return 0;
}