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;
vector<int> g[200111];
vector<int> up[200111];
int dep[200111], sz[200111], id[200111], rid[200111];
int parent[200111][19];
int pmin[200111][19];
int tree[200111];
int N, M, Q, cnt = 0;
struct route {
  int from, to;
};
struct event {
  int x, y, id, sgn;
  bool operator<(event other) const {
    if (x != other.x) return x < other.x;
    return id < other.id;
  }
};
route bus[200111];
route qs[200111];
vector<event> q;
int ans[200111], ans2[200111];
int shift(int x) { return x & (-x); }
void update(int pos, int v) {
  if (pos <= 0) return;
  while (pos <= N) {
    tree[pos] += v;
    pos += shift(pos);
  }
}
int query(int pos) {
  int ret = 0;
  while (pos > 0) {
    ret += tree[pos];
    pos -= shift(pos);
  }
  return ret;
}
void dfs(int v, int d) {
  int i;
  sz[v] = 1, id[v] = ++cnt, rid[id[v]] = v, dep[v] = d;
  for (i = 1; i <= 18; ++i) parent[v][i] = parent[parent[v][i - 1]][i - 1];
  for (auto nv : g[v]) {
    dfs(nv, d + 1);
    sz[v] += sz[nv];
  }
}
void dfs2(int v) {
  for (auto nv : g[v]) {
    dfs2(nv);
    if (pmin[nv][0] != 0) {
      if (pmin[v][0] == 0) pmin[v][0] = pmin[nv][0];
      if (dep[pmin[v][0]] > dep[pmin[nv][0]]) pmin[v][0] = pmin[nv][0];
    }
  }
  for (auto nv : up[v]) {
    if (pmin[v][0] == 0 || dep[pmin[v][0]] > dep[nv]) pmin[v][0] = nv;
  }
}
int LCA(int u, int v) {
  int i;
  if (dep[u] < dep[v]) swap(u, v);
  for (i = 18; i >= 0; --i) {
    if (dep[u] >= (1 << i) + dep[v]) u = parent[u][i];
  }
  if (u == v) return u;
  for (i = 18; i >= 0; --i) {
    if (parent[u][i] != parent[v][i]) {
      u = parent[u][i], v = parent[v][i];
    }
  }
  return parent[u][0];
}
pair<int, int> getp(int v, int anc) {
  int i, ret = 0;
  for (i = 18; i >= 0; --i) {
    if (pmin[v][i] != 0 && dep[pmin[v][i]] > dep[anc]) {
      v = pmin[v][i];
      ret += (1 << i);
    }
  }
  return make_pair(ret, v);
}
int main() {
  int i, j;
  scanf("%d", &N);
  for (i = 2; i <= N; ++i) {
    scanf("%d", &parent[i][0]);
    g[parent[i][0]].push_back(i);
  }
  scanf("%d", &M);
  for (i = 1; i <= M; ++i) scanf("%d%d", &bus[i].from, &bus[i].to);
  dfs(1, 1);
  for (i = 1; i <= M; ++i) {
    if (dep[bus[i].from] < dep[bus[i].to]) swap(bus[i].from, bus[i].to);
    int lca = LCA(bus[i].from, bus[i].to);
    up[bus[i].from].push_back(lca);
    if (bus[i].to != lca) {
      up[bus[i].to].push_back(lca);
      if (id[bus[i].from] > id[bus[i].to]) swap(bus[i].from, bus[i].to);
      q.push_back(event{id[bus[i].from], id[bus[i].to], 0, 0});
    }
  }
  dfs2(1);
  for (j = 1; j <= 18; ++j) {
    for (i = 1; i <= N; ++i) {
      if (pmin[i][j - 1] != 0) pmin[i][j] = pmin[pmin[i][j - 1]][j - 1];
    }
  }
  scanf("%d", &Q);
  for (i = 1; i <= Q; ++i) {
    scanf("%d%d", &qs[i].from, &qs[i].to);
    if (dep[qs[i].from] < dep[qs[i].to]) swap(qs[i].from, qs[i].to);
    int lca = LCA(qs[i].from, qs[i].to);
    auto p1 = getp(qs[i].from, lca), p2 = getp(qs[i].to, lca);
    if (lca == qs[i].to) {
      if (pmin[p1.second][0] != 0 && dep[pmin[p1.second][0]] <= dep[lca]) {
        ans[i] = 1 + p1.first;
      } else {
        ans[i] = -1;
      }
    } else {
      if (pmin[p1.second][0] != 0 && dep[pmin[p1.second][0]] <= dep[lca] &&
          pmin[p2.second][0] != 0 && dep[pmin[p2.second][0]] <= dep[lca]) {
        ans[i] = 2 + p1.first + p2.first;
        int x = p1.second, y = p2.second;
        if (id[x] > id[y]) swap(x, y);
        q.push_back(event{id[x] + sz[x] - 1, id[y] + sz[y] - 1, i, 1});
        q.push_back(event{id[x] - 1, id[y] - 1, i, 1});
        q.push_back(event{id[x] - 1, id[y] + sz[y] - 1, i, -1});
        q.push_back(event{id[x] + sz[x] - 1, id[y] - 1, i, -1});
      } else {
        ans[i] = -1;
      }
    }
  }
  sort(q.begin(), q.end());
  for (i = 0, j = 0; i <= N; ++i) {
    while (j < (int)q.size() && i == q[j].x) {
      if (q[j].id == 0) {
        update(q[j].y, 1);
      } else {
        ans2[q[j].id] += q[j].sgn * query(q[j].y);
      }
      ++j;
    }
  }
  for (i = 1; i <= Q; ++i) {
    if (ans2[i] > 0) {
      ans[i]--;
    }
    printf("%d\n", ans[i]);
  }
  return 0;
}