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 L = 1000000;
char LZH[L];
char *SSS, *TTT;
inline char gc() {
  if (SSS == TTT) {
    TTT = (SSS = LZH) + fread(LZH, 1, L, stdin);
    if (SSS == TTT) return -1;
  }
  return *SSS++;
}
inline int read() {
  int x = 0, f = 1;
  char c = gc();
  for (; c < '0' || c > '9'; c = gc())
    if (c == '-') f = -1;
  for (; c >= '0' && c <= '9'; c = gc()) x = (x << 1) + (x << 3) + c - 48;
  return x * f;
}
const int maxn = 200002;
struct fotiletree {
  struct node {
    int ls, rs, sum;
  } t[maxn * 20];
  int cur;
  int p;
  void update(int &o, int l, int r) {
    t[++cur] = t[o];
    o = cur;
    t[o].sum++;
    if (l == r) return;
    int mid = (l + r) / 2;
    if (p <= mid)
      update(t[o].ls, l, mid);
    else
      update(t[o].rs, mid + 1, r);
  }
  int ql, qr;
  bool count(int lo, int ro, int l, int r) {
    if (ql <= l && qr >= r) return t[ro].sum > t[lo].sum;
    int mid = (l + r) / 2;
    if (ql <= mid && count(t[lo].ls, t[ro].ls, l, mid)) return 1;
    return qr > mid && count(t[lo].rs, t[ro].rs, mid + 1, r);
  }
} t;
struct graph {
  int n, m;
  struct edge {
    int to, next;
  } e[maxn * 2];
  int first[maxn];
  void init(int n) { this->n = n; }
  void addedge(int from, int to) {
    e[++m] = (edge){to, first[from]};
    first[from] = m;
  }
  int dep[maxn], fa[maxn], st[maxn], en[maxn], cl;
  int par[maxn][22];
  void dfs(int u) {
    st[u] = ++cl;
    par[u][0] = fa[u];
    for (int i = 1; i <= 20; i++) par[u][i] = par[par[u][i - 1]][i - 1];
    for (int i = first[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (fa[u] == v) continue;
      fa[v] = u;
      dep[v] = dep[u] + 1;
      dfs(v);
    }
    en[u] = cl;
  }
  int lca(int u, int v) {
    if (dep[u] > dep[v]) swap(u, v);
    int t = dep[v] - dep[u];
    for (int i = 0; i <= 20; i++)
      if (t >> i & 1) v = par[v][i];
    if (u == v) return u;
    for (int i = 20; i >= 0; i--)
      if (par[u][i] != par[v][i]) u = par[u][i], v = par[v][i];
    return par[u][0];
  }
  inline int gt(int x, int y) { return dep[x] < dep[y] ? x : y; }
  int nxt[maxn], f[maxn][22];
  void dfs2(int u) {
    for (int i = first[u]; i; i = e[i].next) {
      int v = e[i].to;
      if (v == fa[u]) continue;
      dfs2(v);
      nxt[u] = gt(nxt[u], nxt[v]);
    }
    f[u][0] = nxt[u];
  }
  vector<int> a[maxn];
  int rt[maxn];
  void add(int u, int v) {
    if (st[u] > st[v]) swap(u, v);
    int lc = lca(u, v);
    nxt[u] = gt(nxt[u], lc);
    nxt[v] = gt(nxt[v], lc);
    a[st[u]].push_back(st[v]);
  }
  void pre() {
    dfs2(1);
    for (int i = 1; i <= 20; i++)
      for (int j = 1; j <= n; j++) f[j][i] = f[f[j][i - 1]][i - 1];
    for (int i = 1; i <= n; i++) {
      rt[i] = rt[i - 1];
      for (int j = 0; j < a[i].size(); j++)
        t.p = a[i][j], t.update(rt[i], 1, n);
    }
  }
  pair<int, int> jump(int u, int to) {
    int ans = 0;
    for (int i = 20; i >= 0; i--)
      if (dep[f[u][i]] > dep[to]) u = f[u][i], ans += 1 << i;
    if (f[u][0] == u) return make_pair(-1, u);
    return make_pair(ans, u);
  }
  int query(int u, int v) {
    if (dep[u] < dep[v]) swap(u, v);
    if (u == v) return 0;
    int lc = lca(u, v);
    pair<int, int> x = jump(u, lc), y = jump(v, lc);
    if (lc == v) return x.first == -1 ? -1 : x.first + 1;
    if (x.first == -1 || y.first == -1) return -1;
    int ans = x.first + y.first + 1;
    int w = x.second, o = y.second;
    if (st[w] > st[o]) swap(w, o);
    t.ql = st[o], t.qr = en[o];
    if (!t.count(rt[st[w] - 1], rt[en[w]], 1, n)) ans++;
    return ans;
  }
} g;
int p[200002];
int main() {
  int n = read();
  g.init(n);
  for (int i = 2; i <= n; i++) {
    p[i] = read();
    g.addedge(i, p[i]);
    g.addedge(p[i], i);
  }
  g.dfs(1);
  for (int i = 1; i <= n; i++) g.nxt[i] = i;
  int m = read();
  while (m--) {
    int u = read(), v = read();
    g.add(u, v);
  }
  g.pre();
  int q = read();
  while (q--) {
    int u = read(), v = read();
    printf("%d\n", g.query(u, v));
  }
}