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>
#pragma GCC optimize("O3")
using namespace std;
template <typename T>
inline void uin(T &a, T b) {
  if (b < a) a = b;
}
template <typename T>
inline void uax(T &a, T b) {
  if (b > a) a = b;
}
const int maxn = 228228;
struct Fenwick {
  vector<int> t;
  int n;
  Fenwick() {}
  Fenwick(int _n) {
    n = _n;
    t.resize(n + 1);
  }
  void upd(int i, int dx) {
    --i;
    for (; i < n; i = (i | (i + 1))) {
      t[i] += dx;
    }
  }
  int getr(int r) {
    --r;
    int res = 0;
    for (; r >= 0; r = (r & (r + 1)) - 1) {
      res += t[r];
    }
    return res;
  }
  int get(int l, int r) { return getr(r) - getr(l - 1); }
};
int n, m, q;
vector<int> g[maxn], pathes[maxn + maxn];
int p[maxn][20], tin[maxn], tout[maxn], deep[maxn], cup[maxn], go[maxn];
int ans[maxn];
int start[maxn + maxn], End[maxn + maxn], gop[maxn][20];
int lft[maxn], rgt[maxn], sz[maxn];
int timer = 1, TIMER = 1;
void dfs(int v, int par = 1) {
  if (v != 1) {
    deep[v] = deep[par] + 1;
  }
  p[v][0] = par;
  for (int i = 1; i < 20; ++i) {
    p[v][i] = p[p[v][i - 1]][i - 1];
  }
  tin[v] = timer++;
  lft[v] = TIMER++;
  sz[v] = 1;
  for (int to : g[v]) {
    if (to != par) {
      dfs(to, v);
      sz[v] += sz[to];
    }
  }
  rgt[v] = lft[v] + sz[v] - 1;
  tout[v] = timer++;
}
bool anc(int u, int v) { return tin[u] <= tin[v] && tout[u] >= tout[v]; }
int get_lca(int u, int v) {
  if (anc(u, v)) return u;
  if (anc(v, u)) return v;
  int k = 19;
  while (k >= 0) {
    if (!anc(p[u][k], v)) {
      u = p[u][k];
    }
    --k;
  }
  return p[u][0];
}
struct event {
  int st, fin, num;
  event() {}
  event(int _st, int _fin, int _num) {
    st = _st;
    fin = _fin;
    num = _num;
  }
};
vector<event> asks[maxn];
void zhfs(int v) {
  go[v] = cup[v];
  for (int to : g[v]) {
    if (to != p[v][0]) {
      zhfs(to);
      if (deep[go[to]] < deep[go[v]]) {
        go[v] = go[to];
      }
    }
  }
}
void zhfs2(int v) {
  gop[v][0] = go[v];
  for (int i = 1; i < 20; ++i) {
    gop[v][i] = gop[gop[v][i - 1]][i - 1];
  }
  for (int to : g[v]) {
    if (to != p[v][0]) {
      zhfs2(to);
    }
  }
}
void precalctamvcetipo() {
  for (int i = 1; i <= (int)n; ++i) cup[i] = i;
  for (int i = 1; i <= (int)m; ++i) {
    int u = start[i], v = End[i];
    int lca = get_lca(u, v);
    if (deep[cup[u]] > deep[lca]) {
      cup[u] = lca;
    }
    if (deep[cup[v]] > deep[lca]) {
      cup[v] = lca;
    }
  }
  zhfs(1);
  zhfs2(1);
}
int solve(int u, int v) {
  int res = 0;
  while (deep[u] > deep[v]) {
    if (deep[gop[u][0]] == deep[u]) return -1;
    ++res;
    u = gop[u][0];
  }
  return res;
}
int goup(int v, int jump) {
  for (int i = 0; i < jump; ++i) {
    v = gop[v][0];
  }
  return v;
}
Fenwick f;
int was[maxn + maxn];
void jfs(int v) {
  for (event ev : asks[v]) {
    was[ev.num] = f.get(lft[ev.fin], rgt[ev.fin]);
  }
  for (int ind : pathes[v]) {
    f.upd(lft[End[ind]], 1);
  }
  for (int to : g[v]) {
    if (to != p[v][0]) {
      jfs(to);
    }
  }
  for (event ev : asks[v]) {
    if (f.get(lft[ev.fin], rgt[ev.fin]) != was[ev.num]) {
      --ans[ev.num];
    }
  }
}
signed main() {
  ios_base::sync_with_stdio(false);
  cin >> n;
  for (int i = 2; i <= n; ++i) {
    int parrrrrrrrrrr;
    cin >> parrrrrrrrrrr;
    g[i].push_back(parrrrrrrrrrr);
    g[parrrrrrrrrrr].push_back(i);
  }
  dfs(1);
  cin >> m;
  for (int i = 1; i <= (int)m; ++i) {
    int u, v;
    cin >> u >> v;
    start[i] = u;
    End[i] = v;
    start[m + i] = v;
    End[m + i] = u;
    pathes[u].push_back(i);
    pathes[v].push_back(m + i);
  }
  precalctamvcetipo();
  cin >> q;
  for (int I = 1; I <= (int)q; ++I) {
    int u, v;
    cin >> u >> v;
    if (anc(u, v)) {
      swap(u, v);
    }
    if (anc(v, u)) {
      ans[I] = solve(u, v);
      continue;
    }
    int lca = get_lca(u, v);
    int a = solve(u, lca);
    int b = solve(v, lca);
    int lu = goup(u, a - 1);
    int lv = goup(v, b - 1);
    if (a == -1 || b == -1) {
      ans[I] = -100;
      continue;
    }
    ans[I] = a + b;
    asks[lu].push_back(event(lu, lv, I));
  }
  f = Fenwick(n);
  jfs(1);
  for (int i = 1; i <= (int)q; ++i) {
    if (ans[i] < -50) {
      cout << "-1\n";
    } else {
      cout << ans[i] << "\n";
    }
  }
  return 0;
}