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;
vector<int> G[200050], bs[200050];
vector<pair<int, int> > ask[200050];
int p[200050][19], g[200050][19];
int dep[200050] = {0};
int lowet[200050], ans[200050], sum[200050];
int tre[400050];
int a[400050], st[200050], ed[200050];
int n, m, qus, tim = 0;
void dfs(int x) {
  a[++tim] = x;
  st[x] = tim;
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    dfs(y);
  }
  a[++tim] = x;
  ed[x] = tim;
}
void lcainit(int x, int fa) {
  dep[x] = dep[fa] + 1;
  p[x][0] = fa;
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    if (y == fa) continue;
    lcainit(y, x);
  }
}
int lca(int x, int y) {
  if (dep[x] > dep[y]) swap(x, y);
  for (int i = 18; i >= 0; i--) {
    if (dep[x] <= dep[y] - (1 << i)) {
      y = p[y][i];
    }
  }
  if (x == y) return x;
  for (int i = 18; i >= 0; i--) {
    if (p[x][i] == p[y][i]) continue;
    x = p[x][i], y = p[y][i];
  }
  return p[x][0];
}
void update(int x, int y) {
  if (x == y) return;
  if (dep[lowet[x]] == 0 || dep[y] < dep[lowet[x]]) lowet[x] = y;
}
void calclow(int x) {
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    calclow(y);
    if (lowet[y]) update(x, lowet[y]);
  }
}
int query(int x) {
  int ans = 0;
  while (x) {
    ans += tre[x];
    x -= (x & -x);
  }
  return ans;
}
void change(int x, int y) {
  for (; x <= n + n; x += (x & -x)) tre[x] += y;
}
void worklow(int x) {
  g[x][0] = lowet[x];
  for (int i = 1; i <= 18; i++) {
    g[x][i] = g[g[x][i - 1]][i - 1];
  }
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    worklow(y);
  }
}
pair<int, int> go(int x, int to) {
  int ans = 0;
  for (int i = 18; i >= 0; i--) {
    if (dep[g[x][i]] > dep[to]) {
      x = g[x][i];
      ans += (1 << i);
    }
  }
  if (dep[g[x][0]] == 0)
    return make_pair(-2, 0);
  else
    return make_pair(ans, x);
}
void solve(int x) {
  for (int i = 0; i < ask[x].size(); i++) {
    int y = ask[x][i].first, id = ask[x][i].second;
    sum[id] = query(ed[y]) - query(st[y]);
  }
  for (int i = 0; i < bs[x].size(); i++) {
    int y = bs[x][i];
    change(ed[y], 1);
  }
  for (int i = 0; i < G[x].size(); i++) {
    int y = G[x][i];
    solve(y);
  }
  for (int i = 0; i < ask[x].size(); i++) {
    int y = ask[x][i].first, id = ask[x][i].second;
    if (sum[id] == query(ed[y]) - query(st[y])) ans[id]++;
  }
}
int main() {
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int f;
    scanf("%d", &f);
    G[f].push_back(i);
  }
  lcainit(1, 0);
  dfs(1);
  for (int i = 1; i <= 18; i++) {
    for (int j = 1; j <= n; j++) {
      p[j][i] = p[p[j][i - 1]][i - 1];
    }
  }
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    bs[x].push_back(y);
    bs[y].push_back(x);
    int z = lca(x, y);
    update(x, z);
    update(y, z);
  }
  calclow(1);
  worklow(1);
  cin >> qus;
  int x, y;
  for (int i = 1; i <= qus; i++) {
    scanf("%d%d", &x, &y);
    int z = lca(x, y);
    if (x == z) {
      ans[i] = go(y, z).first + 1;
      continue;
    }
    if (y == z) {
      ans[i] = go(x, z).first + 1;
      continue;
    }
    pair<int, int> gx = go(x, z);
    pair<int, int> gy = go(y, z);
    int nx = gx.first, ny = gy.first;
    int px = gx.second, py = gy.second;
    if (nx < 0 || ny < 0)
      ans[i] = -1;
    else {
      ans[i] = nx + ny + 1;
      ask[px].push_back(make_pair(py, i));
    }
  }
  solve(1);
  for (int i = 1; i <= qus; i++) printf("%d\n", ans[i]);
  return 0;
}