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;
template <typename T>
void maxtt(T& t1, T t2) {
  t1 = max(t1, t2);
}
template <typename T>
void mintt(T& t1, T t2) {
  t1 = min(t1, t2);
}
bool debug = 0;
int n, m, k;
int dx[4] = {0, 1, 0, -1}, dy[4] = {1, 0, -1, 0};
string direc = "RDLU";
long long ln, lk, lm;
void etp(bool f = 0) {
  puts(f ? "Yes" : "No");
  exit(0);
}
void addmod(int& x, int y, int mod = 998244353) {
  assert(y >= 0);
  x += y;
  if (x >= mod) x -= mod;
  assert(x >= 0 && x < mod);
}
void et() {
  puts("-1");
  exit(0);
}
long long fastPow(long long x, long long y, int mod = 998244353) {
  long long ans = 1;
  while (y > 0) {
    if (y & 1) ans = (x * ans) % mod;
    x = x * x % mod;
    y >>= 1;
  }
  return ans;
}
long long gcd1(long long x, long long y) { return y ? gcd1(y, x % y) : x; }
vector<int> mp[200105];
int d[200105], p[200105][20], A[200105], B[200105];
int lwt[200105][20], Q, qu[200105], qv[200105], Ans[200105];
int lu[200105], lv[200105];
void initlca() {
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i <= n; i++) p[i][j] = p[p[i][j - 1]][j - 1];
}
int lca(int a, int b) {
  if (d[a] > d[b]) swap(a, b);
  int f = d[b] - d[a];
  for (int i = 0; (1 << i) <= f; i++)
    if ((1 << i) & f) b = p[b][i];
  if (a != b) {
    for (int i = 19; i >= 0; i--)
      if (p[a][i] != p[b][i]) {
        a = p[a][i];
        b = p[b][i];
      }
    a = p[a][0];
  }
  return a;
}
pair<int, int> dp[200105];
void dfs(int x) {
  for (int c : mp[x]) {
    dfs(c);
    mintt(dp[x], dp[c]);
  }
  if (dp[x].first <= d[x]) lwt[x][0] = dp[x].second;
}
pair<int, int> fdL(int x, int F) {
  int s = 0;
  for (int j = 19; ~j; j--) {
    if (lwt[x][j] == 0) continue;
    if (d[lwt[x][j]] <= d[F]) continue;
    s += 1 << j;
    x = lwt[x][j];
  }
  return {s, x};
}
vector<int> qs[200105], ways[200105];
int st[200105], ed[200105], cnt, stmp[200105];
int b[200105];
void update(int x, int v) {
  for (int i = x; i <= n; i += i & -i) {
    b[i] += v;
  }
}
int query(int x) {
  int ret = 0;
  for (; x > 0; ret += b[x], x -= x & -x)
    ;
  return ret;
}
int qy(int l, int r) { return query(r) - query(l - 1); }
void dfs2(int x) {
  st[x] = ++cnt;
  for (int c : mp[x]) dfs2(c);
  ed[x] = cnt;
}
void dfs3(int x) {
  for (int id : qs[x]) {
    stmp[id] = qy(st[lv[id]], ed[lv[id]]);
  }
  for (int ot : ways[x]) update(st[ot], 1);
  for (int c : mp[x]) dfs3(c);
  for (int id : qs[x]) {
    if (stmp[id] != qy(st[lv[id]], ed[lv[id]])) Ans[id]--;
  }
}
void fmain(int ID) {
  scanf("%d", &n);
  d[1] = 1;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &p[i][0]);
    mp[p[i][0]].push_back(i);
    d[i] = d[p[i][0]] + 1;
  }
  initlca();
  scanf("%d", &m);
  for (int(i) = 1; (i) <= (int)(n); (i)++) dp[i] = {(1 << 30), (1 << 30)};
  for (int(i) = 1; (i) <= (int)(m); (i)++) {
    scanf("%d%d", A + i, B + i);
    int fa = lca(A[i], B[i]);
    mintt(dp[A[i]], {d[fa], fa});
    mintt(dp[B[i]], {d[fa], fa});
    ways[A[i]].push_back(B[i]);
    ways[B[i]].push_back(A[i]);
  }
  dfs(1);
  for (int j = 1; (1 << j) <= n; j++)
    for (int i = 1; i <= n; i++)
      if (lwt[i][j - 1] && lwt[lwt[i][j - 1]][j - 1]) {
        int tar = lwt[lwt[i][j - 1]][j - 1];
        if (lwt[i][j] == 0 || d[tar] < d[lwt[i][j]]) lwt[i][j] = tar;
      }
  scanf("%d", &Q);
  for (int(i) = 1; (i) <= (int)(Q); (i)++) {
    scanf("%d%d", qu + i, qv + i);
    int fa = lca(qu[i], qv[i]);
    if (d[qv[i]] > d[qu[i]]) swap(qu[i], qv[i]);
    if (fa == qv[i]) {
      auto pp = fdL(qu[i], fa);
      if (lwt[pp.second][0] == 0 || d[lwt[pp.second][0]] > d[fa]) {
        Ans[i] = -1;
        continue;
      }
      assert(d[lwt[pp.second][0]] <= d[fa]);
      Ans[i] = pp.first + 1;
    } else {
      auto pp = fdL(qu[i], fa), ppv = fdL(qv[i], fa);
      if (lwt[pp.second][0] == 0 || d[lwt[pp.second][0]] > d[fa]) {
        Ans[i] = -1;
        continue;
      }
      if (lwt[ppv.second][0] == 0 || d[lwt[ppv.second][0]] > d[fa]) {
        Ans[i] = -1;
        continue;
      }
      lu[i] = pp.second;
      Ans[i] += pp.first + 1;
      lv[i] = ppv.second;
      Ans[i] += ppv.first + 1;
      qs[lu[i]].push_back(i);
    }
  }
  dfs2(1);
  dfs3(1);
  for (int(i) = 1; (i) <= (int)(Q); (i)++) printf("%d\n", Ans[i]);
}
int main() {
  int t = 1;
  for (int(i) = 1; (i) <= (int)(t); (i)++) {
    fmain(i);
  }
  return 0;
}