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 = 1000000007;
const int INF = 2e9;
const long long INFLL = 1e18;
const int MAX_N = 200000;
const int MAX_K = 20;
int N, M, Q;
int p[MAX_N + 1], lv[MAX_N + 1], up[MAX_N + 1][MAX_K + 1], in[MAX_N + 1],
    out[MAX_N + 1], cnt;
bool vst[MAX_N + 1];
vector<int> gp[MAX_N + 1];
int u[MAX_N + 1][MAX_K + 1];
void dfs(int x) {
  in[x] = ++cnt;
  up[x][0] = p[x];
  for (int i = 1; i < MAX_K; i++) {
    up[x][i] = up[up[x][i - 1]][i - 1];
  }
  for (int i : gp[x]) {
    p[i] = x;
    lv[i] = lv[x] + 1;
    dfs(i);
  }
  out[x] = cnt;
}
vector<int> upd[MAX_N + 1];
struct SEG {
  struct NODE {
    int l, r;
    int sum;
  };
  vector<NODE> seg;
  int SZ;
  void add() { seg.push_back({-1, -1, 0}); }
  void Init(int x) {
    SZ = x;
    add();
    init(0, 1, SZ);
  }
  void init(int idx, int s, int e) {
    if (s == e) return;
    seg[idx].l = seg.size();
    add();
    seg[idx].r = seg.size();
    add();
    init(seg[idx].l, s, (s + e) / 2);
    init(seg[idx].r, (s + e) / 2 + 1, e);
  }
  void Update(int x, int y) { update(0, 1, SZ, x, y); }
  void update(int idx, int s, int e, int x, int y) {
    seg[idx].sum += y;
    if (s == e) return;
    if (x <= (s + e) / 2) {
      update(seg[idx].l, s, (s + e) / 2, x, y);
    } else {
      update(seg[idx].r, (s + e) / 2 + 1, e, x, y);
    }
  }
  int Sum(int x, int y) { return sum(0, 1, SZ, x, y); }
  int sum(int idx, int s, int e, int x, int y) {
    if (x <= s && e <= y) {
      return seg[idx].sum;
    }
    if (x > e || y < s) return 0;
    return sum(seg[idx].l, s, (s + e) / 2, x, y) +
           sum(seg[idx].r, (s + e) / 2 + 1, e, x, y);
  }
} Seg;
int lca(int x, int y) {
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (lv[up[x][i]] >= lv[y]) x = up[x][i];
    if (lv[up[y][i]] >= lv[x]) y = up[y][i];
  }
  if (x == y) return x;
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (up[x][i] != up[y][i]) {
      x = up[x][i];
      y = up[y][i];
    }
  }
  return up[x][0];
}
struct ST {
  int x1, x2, idx;
  int num;
};
vector<ST> query[MAX_N + 1];
int ans[MAX_N + 1];
int dist(int x, int y) {
  int ret = 0;
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (lv[u[x][i]] > lv[y]) {
      x = u[x][i];
      ret += (1 << i);
    }
  }
  return ret + 1;
}
int upk(int x, int y) {
  for (int i = MAX_K - 1; i >= 0; i--) {
    if (y >= (1 << i)) {
      y -= (1 << i);
      x = u[x][i];
    }
  }
  return x;
}
void dfs2(int x) {
  for (int i = 0; i < query[x].size(); i++) {
    query[x][i].num = Seg.Sum(query[x][i].x1, query[x][i].x2);
  }
  for (int i : upd[x]) {
    Seg.Update(i, 1);
  }
  for (int i : gp[x]) {
    dfs2(i);
  }
  for (int i = 0; i < query[x].size(); i++) {
    if (query[x][i].num != Seg.Sum(query[x][i].x1, query[x][i].x2)) {
      ans[query[x][i].idx]--;
    }
  }
}
int main() {
  scanf("%d", &N);
  Seg.Init(N);
  for (int i = 2; i <= N; i++) {
    scanf("%d", &p[i]);
    gp[p[i]].push_back(i);
  }
  for (int i = 1; i <= N; i++) {
    u[i][0] = i;
  }
  lv[1] = 1;
  dfs(1);
  scanf("%d", &M);
  for (int i = 1; i <= M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int l = lca(a, b);
    if (lv[u[a][0]] > lv[l]) {
      u[a][0] = l;
    }
    if (lv[u[b][0]] > lv[l]) {
      u[b][0] = l;
    }
    upd[a].push_back(in[b]);
    upd[b].push_back(in[a]);
  }
  for (int i = N; i >= 2; i--) {
    if (lv[u[p[i]][0]] > lv[u[i][0]]) {
      u[p[i]][0] = u[i][0];
    }
  }
  for (int i = 1; i <= N; i++) {
    for (int k = 1; k < MAX_K; k++) {
      u[i][k] = u[u[i][k - 1]][k - 1];
    }
  }
  scanf("%d", &Q);
  for (int i = 0; i < Q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int l = lca(a, b);
    if (lv[u[a][MAX_K - 1]] > lv[l] || lv[u[b][MAX_K - 1]] > lv[l]) {
      ans[i] = -1;
      continue;
    }
    int la, lower_bound;
    if (a == l || b == l) {
      la = dist(a, l);
      lower_bound = dist(b, l);
      if (a == l)
        ans[i] = lower_bound;
      else
        ans[i] = la;
    } else {
      la = dist(a, l);
      lower_bound = dist(b, l);
      ans[i] = la + lower_bound;
      a = upk(a, la - 1);
      b = upk(b, lower_bound - 1);
      query[a].push_back({in[b], out[b], i});
    }
  }
  dfs2(1);
  for (int i = 0; i < Q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}