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 MAXN = 2e5 + 10;
const int MAX_LOG = 20;
vector<int> e[MAXN];
vector<int> fen[MAXN];
vector<int> vertex[MAXN];
vector<pair<int, pair<int, int> > > d[MAXN];
int f[MAXN][MAX_LOG];
int par[MAXN][MAX_LOG];
int x[MAXN];
int y[MAXN];
int b[MAXN];
int st[MAXN];
int ft[MAXN];
int ans[MAXN];
int t = 0;
bool is_par(int v, int u) { return (st[v] <= st[u] && ft[v] >= ft[u]); }
int lca(int v, int u) {
  for (int i = MAX_LOG - 1; i >= 0; i--) {
    if (!is_par(par[v][i], u)) {
      v = par[v][i];
    }
  }
  return (is_par(v, u) ? v : par[v][0]);
}
pair<int, int> mbtlca(int v, int u) {
  int res = 0;
  for (int i = MAX_LOG - 1; i >= 0; i--) {
    if (!is_par(f[v][i], u)) {
      v = f[v][i];
      res += (1 << i);
    }
  }
  return make_pair(v, res);
}
void update(int id, int p) {
  for (; p < fen[id].size(); p += ((p) & -(p))) {
    fen[id][p]++;
  }
}
int get_sum(int id, int p) {
  int sum = 0;
  for (; p > 0; p -= ((p) & -(p))) {
    sum += fen[id][p];
  }
  return sum;
}
void set_dfs(int v) {
  st[v] = ++t;
  for (int i = 0; i < vertex[v].size(); i++) {
    par[vertex[v][i]][0] = v;
    set_dfs(vertex[v][i]);
  }
  ft[v] = t;
}
void f_dfs(int v) {
  for (int i = 0; i < vertex[v].size(); i++) {
    f_dfs(vertex[v][i]);
    if (st[f[vertex[v][i]][0]] < st[f[v][0]]) {
      f[v][0] = f[vertex[v][i]][0];
    }
  }
}
int main() {
  ios_base ::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  for (int i = 2; i <= n; i++) {
    int p;
    cin >> p;
    vertex[p].push_back(i);
  }
  for (int i = 1; i <= n; i++) {
    f[i][0] = i;
  }
  set_dfs(1);
  par[1][0] = 1;
  for (int i = 1; i < MAX_LOG; i++) {
    for (int j = 1; j <= n; j++) {
      par[j][i] = par[par[j][i - 1]][i - 1];
    }
  }
  int m;
  cin >> m;
  for (int i = 1; i <= m; i++) {
    int v, u;
    cin >> v >> u;
    if (st[v] > st[u]) {
      swap(v, u);
    }
    int w = lca(v, u);
    e[w].push_back(st[v]);
    d[w].push_back(make_pair(st[u], make_pair(0, st[v])));
    if (st[w] < st[f[v][0]]) {
      f[v][0] = w;
    }
    if (st[w] < st[f[u][0]]) {
      f[u][0] = w;
    }
  }
  f_dfs(1);
  for (int i = 1; i < MAX_LOG; i++) {
    for (int j = 1; j <= n; j++) {
      f[j][i] = f[f[j][i - 1]][i - 1];
    }
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    cin >> x[i] >> y[i];
    if (st[x[i]] > st[y[i]]) {
      swap(x[i], y[i]);
    }
    if (is_par(x[i], y[i])) {
      pair<int, int> z = mbtlca(y[i], x[i]);
      if (is_par(f[z.first][0], x[i])) {
        ans[i] = z.second + 1;
      } else {
        ans[i] = -1;
      }
    } else {
      pair<int, int> zy = mbtlca(y[i], x[i]), zx = mbtlca(x[i], y[i]);
      if (is_par(f[zy.first][0], x[i]) && is_par(f[zx.first][0], y[i])) {
        ans[i] = zy.second + zx.second + 2;
        x[i] = zx.first;
        y[i] = zy.first;
        int w = lca(x[i], y[i]);
        d[w].push_back(make_pair(ft[y[i]], make_pair(i, 1)));
        d[w].push_back(make_pair(st[y[i]] - 1, make_pair(i, -1)));
      } else {
        ans[i] = -1;
      }
    }
  }
  for (int i = 1; i <= n; i++) {
    sort(e[i].begin(), e[i].end());
    e[i].resize(unique(e[i].begin(), e[i].end()) - e[i].begin());
    fen[i].resize((int)(e[i].size()) + 10);
    for (int j = 0; j < (int)(e[i].size()) + 10; j++) {
      fen[i].push_back(0);
    }
    sort(d[i].begin(), d[i].end());
    for (int j = 0; j < d[i].size(); j++) {
      if (d[i][j].second.first == 0) {
        int p = lower_bound(e[i].begin(), e[i].end(), d[i][j].second.second) -
                e[i].begin() + 1;
        update(i, p);
      } else {
        int l = lower_bound(e[i].begin(), e[i].end(),
                            st[x[d[i][j].second.first]]) -
                e[i].begin(),
            r = upper_bound(e[i].begin(), e[i].end(),
                            ft[x[d[i][j].second.first]]) -
                e[i].begin();
        b[d[i][j].second.first] +=
            d[i][j].second.second * (get_sum(i, r) - get_sum(i, l));
      }
    }
  }
  for (int i = 1; i <= q; i++) {
    cout << ans[i] - (b[i] > 0) << endl;
  }
}