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 = 2e5 + 10;
const int MOD = 1e9 + 7;
struct query {
  int u, v, id;
} qu[N];
int n, m, cnt, cntn;
int st[N], en[N], node[4 * N], check[N];
int lowest[N][20], hi[N], pr[N][30], ans[N];
vector<int> vi[N], events[N];
vector<pair<int, int> > bus[N];
int respm[N];
void upd(int i, int l, int r, int pos, int val) {
  if (pos > r || pos < l || l > r) return;
  if (l == r) {
    node[i] += val;
    return;
  }
  int mid = (l + r) / 2;
  upd(2 * i, l, mid, pos, val);
  upd(2 * i + 1, mid + 1, r, pos, val);
  node[i] = node[2 * i] + node[2 * i + 1];
}
int getm(int i, int l, int r, int ql, int qr) {
  if (l > r || ql > r || qr < l) return 0;
  if (ql <= l && r <= qr) return node[i];
  int mid = (l + r) / 2;
  return getm(2 * i, l, mid, ql, qr) + getm(2 * i + 1, mid + 1, r, ql, qr);
}
void dfs(int pre, int u, bool spm) {
  if (!spm) st[u] = ++cntn;
  pr[u][0] = pre;
  lowest[u][0] = u;
  for (int v : vi[u])
    if (v != pre) {
      hi[v] = hi[u] + 1;
      dfs(u, v, spm);
    }
  if (spm) {
    for (auto v : bus[u]) {
      if (hi[v.second] < hi[lowest[u][0]]) lowest[u][0] = v.second;
    }
    for (int v : vi[u])
      if (v != pre) {
        if (hi[lowest[u][0]] > hi[lowest[v][0]]) lowest[u][0] = lowest[v][0];
      }
  }
  if (!spm) en[u] = cntn;
}
int LCA(int u, int v) {
  if (hi[u] < hi[v]) swap(u, v);
  for (int i = 17; i >= 0; --i)
    if (pr[u][i] != -1 && hi[pr[u][i]] >= hi[v]) u = pr[u][i];
  for (int i = 17; i >= 0; --i)
    if (pr[u][i] != -1 && pr[v][i] != -1 && pr[u][i] != pr[v][i])
      u = pr[u][i], v = pr[v][i];
  if (u != v)
    return pr[u][0];
  else
    return u;
}
void solve(int pre, int u) {
  vector<pair<int, int> > tmp;
  for (int v : events[u]) {
    int tu = qu[v].u, tv = qu[v].v;
    int curu = getm(1, 1, n, st[tu], en[tu]);
    int curv = getm(1, 1, n, st[tv], en[tv]);
    tmp.push_back(pair<int, int>(curu, curv));
  }
  for (auto v : bus[u]) upd(1, 1, n, st[u], 1), upd(1, 1, n, st[v.first], 1);
  for (int v : vi[u])
    if (v != pre) solve(u, v);
  for (int i = 0; i < events[u].size(); ++i) {
    int v = events[u][i];
    int tu = qu[v].u, tv = qu[v].v;
    int curu = getm(1, 1, n, st[tu], en[tu]);
    int curv = getm(1, 1, n, st[tv], en[tv]);
    if (curu > tmp[i].first && tmp[i].second < curv) {
      respm[qu[v].id] = 1;
    } else
      respm[qu[v].id] = 0;
  }
}
signed main() {
  cin >> n;
  memset(pr, -1, sizeof pr);
  memset(lowest, -1, sizeof lowest);
  memset(respm, -1, sizeof respm);
  for (int i = 1; i <= n - 1; ++i) {
    int u;
    cin >> u;
    vi[u].push_back(i + 1);
    vi[i + 1].push_back(u);
  }
  hi[1] = 1;
  dfs(1, 1, 0);
  for (int i = 1; i <= 17; ++i) {
    for (int j = 1; j <= n; ++j)
      if (pr[j][i - 1] != -1) pr[j][i] = pr[pr[j][i - 1]][i - 1];
  }
  cin >> m;
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    int lca = LCA(u, v);
    bus[u].push_back(pair<int, int>(v, lca));
    bus[v].push_back(pair<int, int>(u, lca));
  }
  dfs(1, 1, 1);
  for (int i = 1; i <= n; ++i)
    if (lowest[i][0] == i) lowest[i][0] = -1;
  for (int i = 1; i <= 17; ++i) {
    for (int j = 1; j <= n; ++j)
      if (lowest[j][i - 1] != -1)
        lowest[j][i] = lowest[lowest[j][i - 1]][i - 1];
  }
  int q;
  cin >> q;
  for (int i = 1; i <= q; ++i) {
    int u, v;
    cin >> u >> v;
    int lca = LCA(u, v);
    int tu = u, tv = v;
    for (int j = 17; j >= 0; --j)
      if (lowest[tu][j] != -1) {
        tu = lowest[tu][j];
      }
    for (int j = 17; j >= 0; --j)
      if (lowest[tv][j] != -1) {
        tv = lowest[tv][j];
      }
    if (hi[tu] > hi[lca] || hi[tv] > hi[lca])
      ans[i] = -1;
    else {
      int idem = 0;
      tu = u, tv = v;
      for (int j = 17; j >= 0; --j)
        if (lowest[tv][j] != -1 && hi[lca] < hi[lowest[tv][j]]) {
          tv = lowest[tv][j];
          idem += (1 << j);
        }
      for (int j = 17; j >= 0; --j)
        if (lowest[tu][j] != -1 && hi[lca] < hi[lowest[tu][j]]) {
          tu = lowest[tu][j];
          idem += (1 << j);
        }
      if (lca == u || lca == v) {
        ans[i] = idem + 1;
        continue;
      }
      ans[i] = idem;
      qu[++cnt] = query{tu, tv, i};
      events[tu].push_back(cnt);
      events[tv].push_back(cnt);
    }
  }
  solve(1, 1);
  for (int i = 1; i <= q; ++i) {
    if (ans[i] == -1)
      cout << "-1\n";
    else {
      if (respm[i] == -1)
        cout << ans[i] << '\n';
      else if (respm[i] == 0)
        cout << ans[i] + 2 << '\n';
      else
        cout << ans[i] + 1 << '\n';
    }
  }
}