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 mod = 1e9 + 7;
const int maxn = 2e5 + 5;
vector<int> g[maxn];
int depth = 0, bn = 0, b[maxn << 1];
int f[maxn << 1], dfn[maxn], dr[maxn], ft[maxn];
int fp[maxn][20], ans[maxn], cnt[maxn];
vector<int> fq[maxn];
vector<pair<int, int> > sq[maxn];
void dfs(int u, int fa) {
  int tmp = ++depth;
  b[++bn] = tmp;
  f[tmp] = u;
  dfn[u] = bn;
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs(v, u);
    b[++bn] = tmp;
  }
  dr[u] = depth;
}
int st[maxn << 1][20];
int lg[maxn << 1];
void st_init() {
  for (int i = 2; i < maxn * 2; ++i) lg[i] = lg[i >> 1] + 1;
  for (int i = bn; i >= 1; --i) {
    st[i][0] = b[i];
    for (int j = 1; i + (1 << j) - 1 <= bn; ++j)
      st[i][j] = min(st[i][j - 1], st[i + (1 << (j - 1))][j - 1]);
  }
}
int rmq(int l, int r) {
  int k = lg[r - l + 1];
  return min(st[l][k], st[r - (1 << k) + 1][k]);
}
int lca(int a, int b) {
  if (a == b) return a;
  if (dfn[a] > dfn[b]) swap(a, b);
  int k = rmq(dfn[a], dfn[b]);
  return f[k];
}
void update(int &x, int y) {
  if (y && (!x || dfn[x] > dfn[y])) x = y;
}
void dfs2(int u, int fa) {
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs2(v, u);
    if (fp[v][0] != u) update(fp[u][0], fp[v][0]);
  }
}
void dfs3(int u, int fa) {
  for (int i = 1; i < 20; i++) fp[u][i] = fp[fp[u][i - 1]][i - 1];
  for (auto v : g[u]) {
    if (v == fa) continue;
    dfs3(v, u);
  }
}
void add(int x) {
  while (x < maxn) {
    ft[x]++;
    x += x & (-x);
  }
}
int query(int x) {
  int res = 0;
  while (x > 0) {
    res += ft[x];
    x -= x & (-x);
  }
  return res;
}
int main() {
  int n, m, u, v, i, j, k;
  scanf("%d", &n);
  for (i = 2; i <= n; i++) {
    scanf("%d", &u);
    g[u].push_back(i);
  }
  dfs(1, 0);
  st_init();
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    k = lca(u, v);
    if (k != u) update(fp[u][0], k);
    if (k != v) update(fp[v][0], k);
    if (dfn[u] > dfn[v]) swap(u, v);
    fq[b[dfn[v]]].push_back(b[dfn[u]]);
  }
  dfs2(1, 0);
  dfs3(1, 0);
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d%d", &u, &v);
    k = lca(u, v);
    if (dfn[u] > dfn[v]) swap(u, v);
    for (j = 19; j >= 0; j--) {
      if (dfn[fp[u][j]] > dfn[k]) {
        ans[i] += 1 << j;
        u = fp[u][j];
      }
      if (dfn[fp[v][j]] > dfn[k]) {
        ans[i] += 1 << j;
        v = fp[v][j];
      }
    }
    if (u == k) {
      if (!fp[v][0])
        ans[i] = -1;
      else
        ans[i]++;
    } else {
      if (!fp[u][0] || !fp[v][0])
        ans[i] = -1;
      else {
        ans[i] += 2;
        sq[b[dfn[v]] - 1].push_back(pair<int, int>(u, -i));
        sq[dr[v]].push_back(pair<int, int>(u, i));
      }
    }
  }
  for (i = 0; i <= n; i++) {
    for (auto e : fq[i]) add(e);
    for (auto e : sq[i]) {
      k = query(dr[e.first]) - query(b[dfn[e.first]] - 1);
      if (e.second < 0)
        cnt[-e.second] -= k;
      else
        cnt[e.second] += k;
    }
  }
  for (i = 1; i <= m; i++) {
    if (cnt[i]) ans[i]--;
    printf("%d\n", ans[i]);
  }
  return 0;
}