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>
const int N = 200000;
const int LG = 18;
int n, m, q, p[LG][N], up[LG][N], in[N], out[N], d[N], b[N], ans[N];
std::vector<int> g[N], next[N];
std::vector<std::pair<int, int> > query[N];
void dfs1(int v) {
  static int t = 0;
  in[v] = t++;
  for (int i = 0; i < (int)g[v].size(); ++i) {
    d[g[v][i]] = d[v] + 1;
    dfs1(g[v][i]);
  }
  out[v] = t;
}
bool parent(int u, int v) { return in[u] <= in[v] && out[u] >= out[v]; }
int lca(int u, int v) {
  if (parent(v, u)) return v;
  for (int i = LG - 1; i >= 0; --i)
    if (!parent(p[i][v], u)) v = p[i][v];
  return p[0][v];
}
void apply(int &u, int v) {
  if (d[u] > d[v]) u = v;
}
void dfs2(int v) {
  for (int i = 0; i < (int)g[v].size(); ++i) {
    dfs2(g[v][i]);
    apply(up[0][v], up[0][g[v][i]]);
  }
}
int dist(int u, int v) {
  if (u == v) return 0;
  int r = 0;
  for (int i = LG - 1; i >= 0; --i)
    if (d[up[i][u]] > d[v]) {
      u = up[i][u];
      r += 1 << i;
    }
  return r + 1;
}
int go(int v, int k) {
  for (int i = LG - 1; i >= 0; --i)
    if (1 << i <= k) {
      v = up[i][v];
      k -= 1 << i;
    }
  return v;
}
void add(int i) {
  while (i < n) {
    ++b[i];
    i |= i + 1;
  }
}
int get(int i) {
  int s = 0;
  while (i >= 0) {
    s += b[i];
    i = (i & i + 1) - 1;
  }
  return s;
}
void dfs3(int v) {
  std::vector<int> sum(query[v].size());
  for (int i = 0; i < (int)query[v].size(); ++i)
    sum[i] = get(out[query[v][i].first] - 1) - get(in[query[v][i].first] - 1);
  for (int i = 0; i < (int)next[v].size(); ++i) add(in[next[v][i]]);
  for (int i = 0; i < (int)g[v].size(); ++i) dfs3(g[v][i]);
  for (int i = 0; i < (int)query[v].size(); ++i)
    if (sum[i] !=
        get(out[query[v][i].first] - 1) - get(in[query[v][i].first] - 1))
      --ans[query[v][i].second];
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; ++i) {
    scanf("%d", p[0] + i);
    --p[0][i];
    g[p[0][i]].push_back(i);
  }
  for (int j = 1; j < LG; ++j)
    for (int i = 0; i < n; ++i) p[j][i] = p[j - 1][p[j - 1][i]];
  dfs1(0);
  std::iota(up[0], up[0] + n, 0);
  scanf("%d", &m);
  for (int i = 0; i < m; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    if (in[a] > in[b]) std::swap(a, b);
    next[a].push_back(b);
    int l = lca(a, b);
    apply(up[0][a], l);
    apply(up[0][b], l);
  }
  dfs2(0);
  for (int j = 1; j < LG; ++j)
    for (int i = 0; i < n; ++i) up[j][i] = up[j - 1][up[j - 1][i]];
  scanf("%d", &q);
  for (int i = 0; i < q; ++i) {
    int u, v;
    scanf("%d%d", &u, &v);
    --u;
    --v;
    if (in[u] > in[v]) std::swap(u, v);
    int l = lca(u, v);
    int d1 = dist(u, l), d2 = dist(v, l);
    ans[i] = d1 + d2;
    if (ans[i] > n)
      ans[i] = -1;
    else if (d1 && d2) {
      int last1 = go(u, d1 - 1), last2 = go(v, d2 - 1);
      query[last1].push_back(std::make_pair(last2, i));
    }
  }
  dfs3(0);
  for (int i = 0; i < q; ++i) printf("%d\n", ans[i]);
  return 0;
}