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;
int parent[200001][20];
int reach[200001][20];
int depth[200001];
vector<int> edge[200001];
void dfs_lca(int n, int p = -1, int d = 0) {
  parent[n][0] = p;
  depth[n] = d;
  for (int i = 1; i < 20; i++) {
    if (parent[n][i - 1] != -1) {
      parent[n][i] = parent[parent[n][i - 1]][i - 1];
    } else
      parent[n][i] = -1;
  }
  for (int c : edge[n]) {
    if (c == p) continue;
    dfs_lca(c, n, d + 1);
  }
}
int lca(int a, int b) {
  for (int i = 19; i >= 0; i--) {
    if (depth[b] > depth[a]) swap(a, b);
    if (depth[a] - (1 << i) >= depth[b]) a = parent[a][i];
  }
  for (int i = 19; i >= 0; i--) {
    if (parent[a][i] != parent[b][i]) a = parent[a][i], b = parent[b][i];
  }
  if (a == b) return a;
  return parent[a][0];
}
int dfs_bus(int a, int p = -1) {
  for (int c : edge[a]) {
    if (c == p) continue;
    int res = dfs_bus(c, a);
    if (depth[reach[a][0]] > depth[res]) {
      reach[a][0] = res;
    }
  }
  return reach[a][0];
}
void dfs_bus_lift(int a, int p = -1) {
  for (int i = 1; i < 20; i++) {
    reach[a][i] = reach[reach[a][i - 1]][i - 1];
  }
  for (int c : edge[a]) {
    if (c == p) continue;
    dfs_bus_lift(c, a);
  }
}
int length_to_a(int n, int p) {
  if (n == p) return 0;
  int l = 0;
  for (int i = 19; i >= 0; i--) {
    if (depth[reach[n][i]] > depth[p]) {
      l += (1 << i);
      n = reach[n][i];
    }
  }
  if (depth[reach[n][0]] <= depth[p])
    return l + 1;
  else
    return -1;
}
int jump_to(int n, int j) {
  for (int i = 0; i < 20; i++) {
    if (j & (1 << i)) {
      n = reach[n][i];
    }
  }
  return n;
}
int lef[200001], rig[200001];
int curr;
int tree[800000];
void euler(int n, int p = -1) {
  lef[n] = curr++;
  for (int c : edge[n]) {
    if (c == p) continue;
    euler(c, n);
  }
  rig[n] = curr - 1;
}
void insert(int pos, int n = 1, int l = 0, int r = 200000) {
  if (l > pos || r < pos) return;
  tree[n]++;
  if (l == r) return;
  insert(pos, n * 2, l, (l + r) / 2);
  insert(pos, n * 2 + 1, (l + r) / 2 + 1, r);
}
int get(int rl, int rr, int n = 1, int l = 0, int r = 200000) {
  if (l > rr || r < rl) return 0;
  if (l >= rl && r <= rr) return tree[n];
  return get(rl, rr, n * 2, l, (l + r) / 2) +
         get(rl, rr, n * 2 + 1, (l + r) / 2 + 1, r);
}
int cities, busses, queries;
vector<int> busto[200001];
int ans[200000];
vector<pair<int, int>> query[200001];
void dfs_query(int n, int p = -1) {
  vector<int> pre;
  for (auto &[nxt, qi] : query[n]) {
    pre.push_back(get(lef[nxt], rig[nxt]));
  }
  for (int &nxt : busto[n]) {
    insert(lef[nxt]);
  }
  for (int &c : edge[n]) {
    if (c == p) continue;
    dfs_query(c, n);
  }
  for (int i = 0; i < pre.size(); i++) {
    int nxt = query[n][i].first;
    if (get(lef[nxt], rig[nxt]) > pre[i]) {
      ans[query[n][i].second] += 1;
    } else {
      ans[query[n][i].second] += 2;
    }
  }
}
string prints[1000];
int leafl = 0;
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cin >> cities;
  for (int i = 2; i <= cities; i++) {
    int k;
    cin >> k;
    edge[k].push_back(i);
    edge[i].push_back(k);
  }
  dfs_lca(1);
  euler(1);
  for (int i = 1; i <= cities; i++) reach[i][0] = i;
  cin >> busses;
  for (int i = 0; i < busses; i++) {
    int a, b;
    cin >> a >> b;
    busto[a].push_back(b);
    busto[b].push_back(a);
    int top = lca(a, b);
    if (depth[reach[a][0]] > depth[top]) reach[a][0] = top;
    if (depth[reach[b][0]] > depth[top]) reach[b][0] = top;
  }
  dfs_bus(1);
  dfs_bus_lift(1);
  cin >> queries;
  for (int i = 0; i < queries; i++) {
    int a, b;
    cin >> a >> b;
    int _lca = lca(a, b);
    int la = length_to_a(a, _lca);
    int lb = length_to_a(b, _lca);
    if (la == -1 || lb == -1) {
      ans[i] = -1;
    } else if (a == _lca || b == _lca) {
      ans[i] = la + lb;
    } else {
      ans[i] = la + lb - 2;
      int ta = jump_to(a, la - 1);
      int tb = jump_to(b, lb - 1);
      query[ta].push_back({tb, i});
    }
  }
  dfs_query(1);
  for (int i = 0; i < queries; i++) {
    cout << ans[i] << "\n";
  }
}