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;
using ll = long long;
using K = long double;
const int inf = 1000 * 1000 * 1000 + 7;
const int N = 200005;
const int L = 20;
struct SegTree {
  int n;
  vector<set<int>> t;
  SegTree() {}
  SegTree(vector<pair<int, int>> a) {
    if (a.empty()) return;
    n = ((int)(a).size());
    t.resize(4 * n);
    sort(a.begin(), a.end());
    build(1, 0, n - 1, a);
  }
  void build(int v, int tl, int tr, const vector<pair<int, int>>& a) {
    for (int i = tl; i <= tr; ++i) {
      t[v].insert(a[i].second);
    }
    if (tl == tr) {
      return;
    }
    int tm = (tl + tr) / 2;
    build(2 * v, tl, tm, a);
    build(2 * v + 1, tm + 1, tr, a);
  }
  int go(int v, int tl, int tr, int l, int r, int l2, int r2) {
    if (l > tr || r < tl) return 0;
    if (l <= tl && r >= tr) {
      auto it = t[v].lower_bound(l2);
      return it != t[v].end() && *it <= r2;
    }
    int tm = (tl + tr) / 2;
    return go(2 * v, tl, tm, l, r, l2, r2) |
           go(2 * v + 1, tm + 1, tr, l, r, l2, r2);
  }
  int go(int l1, int r1, int l2, int r2) {
    if (t.empty() || l1 > r1) return 0;
    return go(1, 0, n - 1, l1, r1, l2, r2);
  }
} tree[N];
vector<pair<int, int>> pts[N];
int n, m, q;
vector<int> g[N];
int par[L][N];
int f[N];
int tin[N], timer, size[N];
int result[N];
int minTree(int a, int b) { return tin[a] < tin[b] ? a : b; }
void dfs(int v, int pr = 0) {
  tin[v] = timer++;
  size[v] = 1;
  par[0][v] = pr;
  for (int i = 1; i < L; ++i) {
    par[i][v] = par[i - 1][par[i - 1][v]];
  }
  for (auto& to : g[v]) {
    dfs(to, v);
    size[v] += size[to];
  }
}
int line(int a, int b) {
  return tin[a] <= tin[b] && tin[a] + size[a] >= tin[b] + size[b];
}
int lca(int a, int b) {
  if (line(a, b)) return a;
  if (line(b, a)) return b;
  for (int i = L - 1; i >= 0; --i) {
    if (!line(par[i][a], b)) {
      a = par[i][a];
    }
  }
  return par[0][a];
}
int fup[L][N];
void go(int v) {
  for (auto& to : g[v]) {
    go(to);
    f[v] = minTree(f[v], f[to]);
  }
}
void calc(int v) {
  fup[0][v] = f[v];
  for (int i = 1; i < L; ++i) {
    fup[i][v] = fup[i - 1][fup[i - 1][v]];
  }
  for (auto& to : g[v]) {
    calc(to);
  }
}
pair<int, int> up(int a, int c) {
  int cnt = 0;
  for (int i = L - 1; i >= 0; --i) {
    if (!line(fup[i][a], c)) {
      a = fup[i][a];
      cnt += (1 << i);
    }
  }
  return {a, cnt};
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cin >> n;
  for (int i = 0; i < (n); ++i) {
    f[i] = i;
  }
  for (int i = 1; i < n; ++i) {
    int par;
    cin >> par;
    g[par - 1].push_back(i);
  }
  dfs(0);
  cin >> m;
  for (int i = 0; i < (m); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    if (tin[a] > tin[b]) {
      swap(a, b);
    }
    int c = lca(a, b);
    f[a] = minTree(f[a], c);
    f[b] = minTree(f[b], c);
    pts[c].emplace_back(tin[a], tin[b]);
  }
  for (int i = 0; i < (m); ++i) {
    sort(pts[i].begin(), pts[i].end());
    tree[i] = SegTree(pts[i]);
  }
  go(0);
  calc(0);
  cin >> q;
  for (int i = 0; i < (q); ++i) {
    int a, b;
    cin >> a >> b;
    --a;
    --b;
    int c = lca(a, b);
    auto x = up(a, c);
    auto y = up(b, c);
    if (tin[x.first] > tin[y.first]) swap(x, y);
    if (tin[f[x.first]] > tin[c] || tin[f[y.first]] > tin[c]) {
      result[i] = -1;
      continue;
    }
    int l =
        lower_bound(pts[c].begin(), pts[c].end(), make_pair(tin[x.first], -1)) -
        pts[c].begin();
    int r = lower_bound(pts[c].begin(), pts[c].end(),
                        make_pair(tin[x.first] + size[x.first], -1)) -
            pts[c].begin() - 1;
    result[i] = x.second + y.second + 2;
    if (x.first == c) {
      --result[i];
      continue;
    }
    result[i] -=
        tree[c].go(l, r, tin[y.first], tin[y.first] + size[y.first] - 1);
  }
  for (int i = 0; i < (q); ++i) {
    cout << result[i] << '\n';
  }
}