#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline void chkmax(T &x, const T2 &y) {
  if (x < y) x = y;
}
template <class T, class T2>
inline void chkmin(T &x, const T2 &y) {
  if (x > y) x = y;
}
const int MAXN = (int)3e5 + 42 + 17;
const int MAXLOG = 20;
int n, m, q;
vector<int> G[MAXN];
vector<int> li[MAXN];
pair<int, int> e[MAXN];
int answer[MAXN];
template <class T>
struct fenwick {
  int sz;
  T tr[MAXN];
  void init(int n) {
    sz = n + 1;
    memset(tr, 0, sizeof(tr));
  }
  T query(int idx) {
    T ans = 0;
    for (; idx >= 1; idx -= (idx & -idx)) ans += tr[idx];
    return ans;
  }
  void update(int idx, T val) {
    if (idx <= 0) return;
    for (; idx <= sz; idx += (idx & -idx)) tr[idx] += val;
  }
  T query(int l, int r) { return query(r) - query(l - 1); }
};
int qu[MAXN], qv[MAXN];
bool add1[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int pr;
    cin >> pr;
    G[pr].push_back(i + 2);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> e[i].first >> e[i].second;
    li[e[i].first].push_back(e[i].second);
    li[e[i].second].push_back(e[i].first);
  }
  cin >> q;
  for (int i = 0; i < q; i++) cin >> qu[i] >> qv[i];
}
int st[MAXN], en[MAXN], dfs_time = 0;
int par[MAXN][MAXLOG];
int dep[MAXN];
vector<int> que[MAXN];
vector<int> to_rem[MAXN];
fenwick<int> t;
void dfs_lca(int u, int d = 0) {
  dep[u] = d;
  st[u] = ++dfs_time;
  for (int i = 1; i < MAXLOG; i++) par[u][i] = par[par[u][i - 1]][i - 1];
  for (int v : G[u])
    if (v != par[u][0]) {
      par[v][0] = u;
      dfs_lca(v, d + 1);
    }
  en[u] = dfs_time;
}
inline bool upper(int u, int v) { return st[u] <= st[v] && en[v] <= en[u]; }
int lca(int u, int v) {
  if (upper(u, v)) return u;
  if (upper(v, u)) return v;
  int a = u;
  for (int i = MAXLOG - 1; i >= 0; i--)
    if (!upper(par[a][i], v)) a = par[a][i];
  return par[a][0];
}
int parent(int u, int up) {
  int a = u;
  for (int i = MAXLOG - 1; i >= 0; i--)
    if (up & (1 << i)) a = par[a][i];
  return a;
}
void lca_precompute(int root) {
  for (int i = 0; i < MAXLOG; i++) par[root][i] = root;
  dfs_time = 0;
  dfs_lca(root);
}
int tr_sz[MAXN];
void pre_dfs(int u, int pr) {
  tr_sz[u] = li[u].size() + 1 + to_rem[u].size();
  for (int v : G[u])
    if (v != pr) {
      pre_dfs(v, u);
      tr_sz[u] += tr_sz[v];
    }
}
void add_vertex(int u) {
  for (auto it : li[u]) t.update(st[it], 1);
}
void clear(int u, int pr) {
  for (auto it : li[u]) t.update(st[it], -1);
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], 1);
    t.update(st[vv], 1);
  }
  for (int v : G[u])
    if (v != pr) clear(v, u);
}
void add(int u, int pr) {
  add_vertex(u);
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], -1);
    t.update(st[vv], -1);
  }
  for (int v : G[u])
    if (v != pr) add(v, u);
}
void dfs(int u, int pr, int keep) {
  pair<int, int> mx = {-1, -1};
  for (int v : G[u])
    if (v != pr) mx = max(mx, {tr_sz[v], v});
  for (int v : G[u])
    if (v != pr && v != mx.second) dfs(v, u, 0);
  if (mx.second != -1) dfs(mx.second, u, 1);
  for (int v : G[u])
    if (v != pr && v != mx.second) add(v, u);
  add_vertex(u);
  for (int i : que[u])
    if (t.query(st[qv[i]], en[qv[i]])) add1[i] = 1;
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], -1);
    t.update(st[vv], -1);
  }
  if (keep) return;
  clear(u, pr);
}
int up[MAXN][20];
void get_up(int u, int pr) {
  up[u][0] = u;
  for (int x : li[u]) {
    int ax = lca(x, u);
    if (up[u][0] == -1 || dep[ax] < dep[up[u][0]]) up[u][0] = ax;
  }
  for (int v : G[u])
    if (v != pr) {
      get_up(v, u);
      if (up[u][0] == -1 || dep[up[v][0]] < dep[up[u][0]]) up[u][0] = up[v][0];
    }
}
int go_up(int u, int l, int idx) {
  for (int o = 19; o >= 0; o--)
    if (up[u][o] != -1 && !upper(up[u][o], l)) {
      u = up[u][o];
      answer[idx] += (1 << o);
    }
  return u;
}
void solve() {
  lca_precompute(1);
  get_up(1, 1);
  for (int i = 1; i < 20; i++)
    for (int x = 1; x <= n; x++) up[x][i] = up[up[x][i - 1]][i - 1];
  for (int i = 0; i < q; i++) {
    int anc = lca(qu[i], qv[i]);
    qu[i] = go_up(qu[i], anc, i);
    qv[i] = go_up(qv[i], anc, i);
    if (qu[i] != anc && (up[qu[i]][0] == -1 || dep[up[qu[i]][0]] > dep[anc])) {
      answer[i] = -1;
      continue;
    }
    if (qv[i] != anc && (up[qv[i]][0] == -1 || dep[up[qv[i]][0]] > dep[anc])) {
      answer[i] = -1;
      continue;
    }
    if (qu[i] == anc || qv[i] == anc) add1[i] = 1;
    que[qu[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    int u = e[i].first, v = e[i].second;
    to_rem[lca(u, v)].push_back(i);
  }
  t.init(n + 2);
  pre_dfs(1, 1);
  dfs(1, 1, 0);
  for (int i = 0; i < q; i++) {
    if (answer[i] != -1) {
      if (!add1[i])
        answer[i] += 2;
      else
        answer[i] += 1;
    }
    cout << answer[i] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}

### Prompt

Construct a CPP code solution to the problem outlined:

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. 

### Response

```cpp
#include <bits/stdc++.h>
using namespace std;
template <class T, class T2>
inline void chkmax(T &x, const T2 &y) {
  if (x < y) x = y;
}
template <class T, class T2>
inline void chkmin(T &x, const T2 &y) {
  if (x > y) x = y;
}
const int MAXN = (int)3e5 + 42 + 17;
const int MAXLOG = 20;
int n, m, q;
vector<int> G[MAXN];
vector<int> li[MAXN];
pair<int, int> e[MAXN];
int answer[MAXN];
template <class T>
struct fenwick {
  int sz;
  T tr[MAXN];
  void init(int n) {
    sz = n + 1;
    memset(tr, 0, sizeof(tr));
  }
  T query(int idx) {
    T ans = 0;
    for (; idx >= 1; idx -= (idx & -idx)) ans += tr[idx];
    return ans;
  }
  void update(int idx, T val) {
    if (idx <= 0) return;
    for (; idx <= sz; idx += (idx & -idx)) tr[idx] += val;
  }
  T query(int l, int r) { return query(r) - query(l - 1); }
};
int qu[MAXN], qv[MAXN];
bool add1[MAXN];
void read() {
  cin >> n;
  for (int i = 0; i < n - 1; i++) {
    int pr;
    cin >> pr;
    G[pr].push_back(i + 2);
  }
  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> e[i].first >> e[i].second;
    li[e[i].first].push_back(e[i].second);
    li[e[i].second].push_back(e[i].first);
  }
  cin >> q;
  for (int i = 0; i < q; i++) cin >> qu[i] >> qv[i];
}
int st[MAXN], en[MAXN], dfs_time = 0;
int par[MAXN][MAXLOG];
int dep[MAXN];
vector<int> que[MAXN];
vector<int> to_rem[MAXN];
fenwick<int> t;
void dfs_lca(int u, int d = 0) {
  dep[u] = d;
  st[u] = ++dfs_time;
  for (int i = 1; i < MAXLOG; i++) par[u][i] = par[par[u][i - 1]][i - 1];
  for (int v : G[u])
    if (v != par[u][0]) {
      par[v][0] = u;
      dfs_lca(v, d + 1);
    }
  en[u] = dfs_time;
}
inline bool upper(int u, int v) { return st[u] <= st[v] && en[v] <= en[u]; }
int lca(int u, int v) {
  if (upper(u, v)) return u;
  if (upper(v, u)) return v;
  int a = u;
  for (int i = MAXLOG - 1; i >= 0; i--)
    if (!upper(par[a][i], v)) a = par[a][i];
  return par[a][0];
}
int parent(int u, int up) {
  int a = u;
  for (int i = MAXLOG - 1; i >= 0; i--)
    if (up & (1 << i)) a = par[a][i];
  return a;
}
void lca_precompute(int root) {
  for (int i = 0; i < MAXLOG; i++) par[root][i] = root;
  dfs_time = 0;
  dfs_lca(root);
}
int tr_sz[MAXN];
void pre_dfs(int u, int pr) {
  tr_sz[u] = li[u].size() + 1 + to_rem[u].size();
  for (int v : G[u])
    if (v != pr) {
      pre_dfs(v, u);
      tr_sz[u] += tr_sz[v];
    }
}
void add_vertex(int u) {
  for (auto it : li[u]) t.update(st[it], 1);
}
void clear(int u, int pr) {
  for (auto it : li[u]) t.update(st[it], -1);
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], 1);
    t.update(st[vv], 1);
  }
  for (int v : G[u])
    if (v != pr) clear(v, u);
}
void add(int u, int pr) {
  add_vertex(u);
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], -1);
    t.update(st[vv], -1);
  }
  for (int v : G[u])
    if (v != pr) add(v, u);
}
void dfs(int u, int pr, int keep) {
  pair<int, int> mx = {-1, -1};
  for (int v : G[u])
    if (v != pr) mx = max(mx, {tr_sz[v], v});
  for (int v : G[u])
    if (v != pr && v != mx.second) dfs(v, u, 0);
  if (mx.second != -1) dfs(mx.second, u, 1);
  for (int v : G[u])
    if (v != pr && v != mx.second) add(v, u);
  add_vertex(u);
  for (int i : que[u])
    if (t.query(st[qv[i]], en[qv[i]])) add1[i] = 1;
  for (auto idx : to_rem[u]) {
    int uu = e[idx].first, vv = e[idx].second;
    t.update(st[uu], -1);
    t.update(st[vv], -1);
  }
  if (keep) return;
  clear(u, pr);
}
int up[MAXN][20];
void get_up(int u, int pr) {
  up[u][0] = u;
  for (int x : li[u]) {
    int ax = lca(x, u);
    if (up[u][0] == -1 || dep[ax] < dep[up[u][0]]) up[u][0] = ax;
  }
  for (int v : G[u])
    if (v != pr) {
      get_up(v, u);
      if (up[u][0] == -1 || dep[up[v][0]] < dep[up[u][0]]) up[u][0] = up[v][0];
    }
}
int go_up(int u, int l, int idx) {
  for (int o = 19; o >= 0; o--)
    if (up[u][o] != -1 && !upper(up[u][o], l)) {
      u = up[u][o];
      answer[idx] += (1 << o);
    }
  return u;
}
void solve() {
  lca_precompute(1);
  get_up(1, 1);
  for (int i = 1; i < 20; i++)
    for (int x = 1; x <= n; x++) up[x][i] = up[up[x][i - 1]][i - 1];
  for (int i = 0; i < q; i++) {
    int anc = lca(qu[i], qv[i]);
    qu[i] = go_up(qu[i], anc, i);
    qv[i] = go_up(qv[i], anc, i);
    if (qu[i] != anc && (up[qu[i]][0] == -1 || dep[up[qu[i]][0]] > dep[anc])) {
      answer[i] = -1;
      continue;
    }
    if (qv[i] != anc && (up[qv[i]][0] == -1 || dep[up[qv[i]][0]] > dep[anc])) {
      answer[i] = -1;
      continue;
    }
    if (qu[i] == anc || qv[i] == anc) add1[i] = 1;
    que[qu[i]].push_back(i);
  }
  for (int i = 0; i < m; i++) {
    int u = e[i].first, v = e[i].second;
    to_rem[lca(u, v)].push_back(i);
  }
  t.init(n + 2);
  pre_dfs(1, 1);
  dfs(1, 1, 0);
  for (int i = 0; i < q; i++) {
    if (answer[i] != -1) {
      if (!add1[i])
        answer[i] += 2;
      else
        answer[i] += 1;
    }
    cout << answer[i] << '\n';
  }
}
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  read();
  solve();
  return 0;
}

```