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 long long N = 2e5 + 2;
vector<long long> lis[N], adj[N], uwu[N];
vector<pair<long long, long long> > que[N];
long long n, level[N], ancestor[N][22], size[N],
    now = 0, pos[N], ohyeah[N][22], it[4 * N], wow[N], dizz[N], rmq[N][22],
    rmqidx[N][22], haizz[N], ans[N];
long long lazy[4 * N];
void dfs(long long x) {
  now++;
  pos[x] = now;
  wow[now] = x;
  size[x] = 1;
  long long i;
  for (i = 1; i <= 20; i++) {
    ancestor[x][i] = ancestor[ancestor[x][i - 1]][i - 1];
  }
  for (i = 0; i < adj[x].size(); i++) {
    level[adj[x][i]] = level[x] + 1;
    ancestor[adj[x][i]][0] = x;
    dfs(adj[x][i]);
    size[x] += size[adj[x][i]];
  }
}
long long findd(long long x, long long k) {
  long long y;
  while (k) {
    y = log2(k);
    x = ancestor[x][y];
    k -= (1 << y);
  }
  return x;
}
long long LCA(long long x, long long y) {
  if (level[x] > level[y]) {
    x = findd(x, level[x] - level[y]);
  }
  y = findd(y, level[y] - level[x]);
  if (x == y) {
    return x;
  }
  for (long long i = 20; i >= 0; i--) {
    if (ancestor[x][i] != ancestor[y][i]) {
      x = ancestor[x][i];
      y = ancestor[y][i];
    }
  }
  return ancestor[x][0];
}
long long getminidx(long long x, long long y) {
  long long z = log2(y - x + 1);
  if (rmq[x][z] > rmq[y - (1 << z) + 1][z]) {
    return rmqidx[y - (1 << z) + 1][z];
  }
  return rmqidx[x][z];
}
void upd(long long idx, long long l, long long r, long long lef, long long rig,
         long long val) {
  if (l > rig || r < lef) {
    return;
  }
  if (l >= lef && r <= rig) {
    lazy[idx] += val;
    it[idx] += val * (r - l + 1);
    return;
  }
  if (lazy[idx] != 0) {
    it[2 * idx] += lazy[idx] * ((l + r) / 2 - l + 1);
    it[2 * idx + 1] += lazy[idx] * (r - (l + r) / 2);
    lazy[2 * idx] += lazy[idx];
    lazy[2 * idx + 1] += lazy[idx];
    lazy[idx] = 0;
  }
  upd(2 * idx, l, (l + r) / 2, lef, rig, val);
  upd(2 * idx + 1, (l + r) / 2 + 1, r, lef, rig, val);
  it[idx] = it[2 * idx] + it[2 * idx + 1];
}
long long getsum(long long idx, long long l, long long r, long long lef,
                 long long rig) {
  if (l > rig || r < lef) {
    return 0;
  }
  if (l >= lef && r <= rig) {
    return it[idx];
  }
  if (lazy[idx] != 0) {
    it[2 * idx] += lazy[idx] * ((l + r) / 2 - l + 1);
    it[2 * idx + 1] += lazy[idx] * (r - (l + r) / 2);
    lazy[2 * idx] += lazy[idx];
    lazy[2 * idx + 1] += lazy[idx];
    lazy[idx] = 0;
  }
  return getsum(2 * idx, l, (l + r) / 2, lef, rig) +
         getsum(2 * idx + 1, (l + r) / 2 + 1, r, lef, rig);
}
void dfs1(long long x) {
  long long i;
  for (i = 0; i < que[x].size(); i++) {
    uwu[x].push_back(getsum(1, 1, n, pos[que[x][i].first],
                            pos[que[x][i].first] + size[que[x][i].first] - 1));
  }
  for (i = 0; i < adj[x].size(); i++) {
    dfs1(adj[x][i]);
  }
  for (i = 0; i < lis[x].size(); i++) {
    upd(1, 1, n, pos[lis[x][i]], pos[lis[x][i]], 1);
  }
  for (i = 0; i < que[x].size(); i++) {
    if (uwu[x][i] != getsum(1, 1, n, pos[que[x][i].first],
                            pos[que[x][i].first] + size[que[x][i].first] - 1)) {
      ans[que[x][i].second]--;
    }
  }
}
signed main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  long long i, j, k, l, m, q, xd, xd1, cac;
  cin >> n;
  for (i = 2; i <= n; i++) {
    cin >> j;
    adj[j].push_back(i);
  }
  dfs(1);
  cin >> m;
  for (i = 1; i <= n; i++) {
    dizz[i] = level[i];
    haizz[i] = i;
  }
  for (i = 1; i <= m; i++) {
    cin >> j >> k;
    if (level[j] > level[k]) {
      swap(j, k);
    }
    l = LCA(j, k);
    if (l == j) {
      if (dizz[k] > level[j]) {
        haizz[k] = j;
        dizz[k] = level[j];
      }
    } else {
      if (dizz[k] > level[l]) {
        haizz[k] = l;
        dizz[k] = level[l];
      }
      if (dizz[j] > level[l]) {
        haizz[j] = l;
        dizz[j] = level[l];
      }
      lis[j].push_back(k);
      lis[k].push_back(j);
    }
  }
  for (i = 1; i <= n; i++) {
    rmq[i][0] = dizz[wow[i]];
    rmqidx[i][0] = wow[i];
  }
  for (i = 1; i <= 20; i++) {
    for (j = 1; j <= n - (1 << i) + 1; j++) {
      if (rmq[j][i - 1] > rmq[j + (1 << (i - 1))][i - 1]) {
        rmq[j][i] = rmq[j + (1 << (i - 1))][i - 1];
        rmqidx[j][i] = rmqidx[j + (1 << (i - 1))][i - 1];
      } else {
        rmq[j][i] = rmq[j][i - 1];
        rmqidx[j][i] = rmqidx[j][i - 1];
      }
    }
  }
  for (i = 1; i <= n; i++) {
    ohyeah[i][0] = haizz[getminidx(pos[i], pos[i] + size[i] - 1)];
  }
  for (j = 1; j <= 20; j++) {
    for (i = 1; i <= n; i++) {
      ohyeah[i][j] = ohyeah[ohyeah[i][j - 1]][j - 1];
    }
  }
  cin >> q;
  for (i = 1; i <= q; i++) {
    cin >> j >> k;
    cac = LCA(j, k);
    if (level[j] > level[k]) {
      swap(j, k);
    }
    if (cac == j) {
      xd = k;
      for (l = 20; l >= 0; l--) {
        if (level[ohyeah[xd][l]] > level[cac]) {
          xd = ohyeah[xd][l];
          ans[i] += (1 << l);
        }
      }
      if (level[ohyeah[xd][0]] > level[cac]) {
        ans[i] = -1;
      } else {
        ans[i]++;
      }
      continue;
    }
    xd = j;
    for (l = 20; l >= 0; l--) {
      if (level[ohyeah[xd][l]] > level[cac]) {
        xd = ohyeah[xd][l];
        ans[i] += (1 << l);
      }
    }
    if (level[ohyeah[xd][0]] > level[cac]) {
      ans[i] = -1;
      continue;
    }
    xd1 = k;
    for (l = 20; l >= 0; l--) {
      if (level[ohyeah[xd1][l]] > level[cac]) {
        xd1 = ohyeah[xd1][l];
        ans[i] += (1 << l);
      }
    }
    if (level[ohyeah[xd1][0]] > level[cac]) {
      ans[i] = -1;
      continue;
    }
    ans[i] += 2;
    que[xd].push_back({xd1, i});
  }
  dfs1(1);
  for (i = 1; i <= q; i++) {
    cout << ans[i] << "\n";
  }
}