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 N = 200010;
const int logs = 20;
vector<int> v[N];
vector<int> links[N];
vector<pair<int, int> > qry[N];
int dep[N];
int fa[N][logs];
int st[N], ed[N], times;
int low[N][logs];
void update(int &first, int second) {
  if (dep[first] > dep[second]) first = second;
}
void dfs(int u, int p) {
  st[u] = ++times;
  for (int i = 0; i < v[u].size(); i++) {
    int first = v[u][i];
    if (first == p) continue;
    fa[first][0] = u;
    dep[first] = dep[u] + 1;
    for (int j = 1; j < logs; j++) fa[first][j] = fa[fa[first][j - 1]][j - 1];
    dfs(first, u);
  }
  ed[u] = times;
}
int get_lca(int p, int q) {
  if (dep[p] < dep[q]) swap(p, q);
  for (int i = logs - 1; i >= 0; i--) {
    if (dep[p] - (1 << i) >= dep[q]) p = fa[p][i];
  }
  if (p == q) return p;
  for (int i = logs - 1; i >= 0; i--) {
    if (fa[p][i] && fa[q][i] && fa[p][i] != fa[q][i]) {
      p = fa[p][i];
      q = fa[q][i];
    }
  }
  return fa[p][0];
}
void dfs1(int u, int p) {
  for (int i = 0; i < v[u].size(); i++) {
    int first = v[u][i];
    if (first == p) continue;
    dfs1(first, u);
    update(low[u][0], low[first][0]);
  }
}
int get_cost(int first, int lca, int &cost) {
  cost = 0;
  if (dep[low[first][logs - 1]] > dep[lca]) {
    return -1;
  }
  for (int i = logs - 1; i >= 0; i--) {
    if (dep[low[first][i]] <= dep[lca]) continue;
    cost |= (1 << i);
    first = low[first][i];
  }
  return first;
}
int c[N];
int lowbit(int first) { return first & (-first); }
void add(int first, int second) {
  for (int i = first; i < N; i += lowbit(i)) c[i] += second;
}
int query(int first) {
  int ans = 0;
  for (int i = first; i > 0; i -= lowbit(i)) ans += c[i];
  return ans;
}
int ans[N];
int can[N];
void dfs2(int u, int p) {
  for (int i = 0; i < qry[u].size(); i++) {
    int first = qry[u][i].first;
    int id = qry[u][i].second;
    can[id] -= query(ed[first]) - query(st[first] - 1);
  }
  for (int i = 0; i < links[u].size(); i++) {
    int second = links[u][i];
    add(st[second], 1);
  }
  for (int i = 0; i < v[u].size(); i++) {
    int first = v[u][i];
    if (first == p) continue;
    dfs2(first, u);
  }
  for (int i = 0; i < qry[u].size(); i++) {
    int first = qry[u][i].first;
    int id = qry[u][i].second;
    can[id] += query(ed[first]) - query(st[first] - 1);
  }
}
int main() {
  int n, m, r, first, second;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    scanf("%d", &first);
    v[i + 1].push_back(first);
    v[first].push_back(i + 1);
  }
  dfs(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= n; i++) low[i][0] = i;
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &first, &second);
    int lca = get_lca(first, second);
    if (lca != first && lca != second) {
      links[first].push_back(second);
      links[second].push_back(first);
    }
    update(low[first][0], lca);
    update(low[second][0], lca);
  }
  dfs1(1, 0);
  for (int i = 1; i < logs; i++) {
    for (int j = 1; j <= n; j++) {
      low[j][i] = low[low[j][i - 1]][i - 1];
    }
  }
  scanf("%d", &m);
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &first, &second);
    if (st[first] > st[second]) swap(first, second);
    int lca = get_lca(first, second);
    int lowx, tx = get_cost(first, lca, lowx);
    int lowy, ty = get_cost(second, lca, lowy);
    if (tx == -1 || ty == -1) {
      ans[i] = -1;
      continue;
    }
    if (lca == first) {
      ans[i] = lowy + 1;
      continue;
    }
    if (lca == second) {
      ans[i] = lowx + 1;
      continue;
    }
    ans[i] = lowx + lowy + 2;
    qry[tx].push_back(make_pair(ty, i));
  }
  dfs2(1, 0);
  for (int i = 1; i <= m; i++) {
    if (ans[i] != -1) ans[i] -= can[i] > 0;
    printf("%d\n", ans[i]);
  }
  return 0;
}