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 maxn = 2e5 + 10, lgn = 19;
int n, m, q, dep[maxn], par[maxn][lgn], U[maxn << 1], V[maxn << 1],
    f[maxn][lgn], seg[lgn][maxn << 2], ans[maxn], dfn[maxn], End[maxn], clk,
    q_n, fen[maxn], res[maxn];
bool tag[maxn];
vector<int> g[maxn];
struct query {
  int x, y, i;
  query() {}
  query(int a, int b, int i) : x(a), y(b), i(i) {}
} qry[maxn << 2], info[maxn << 1];
void dfs1(int u, int p) {
  dfn[u] = ++clk;
  par[u][0] = p;
  dep[u] = dep[p] + 1;
  for (int i = 1; i < lgn; ++i) {
    par[u][i] = par[par[u][i - 1]][i - 1];
  }
  for (int &v : g[u]) {
    if (v != p) {
      dfs1(v, u);
    }
  }
  End[u] = clk;
  return;
}
int lca(int u, int v) {
  if (dep[u] < dep[v]) {
    swap(u, v);
  }
  int dlt = dep[u] - dep[v];
  for (int i = 0; i < lgn; ++i) {
    if ((dlt >> i) & 1) {
      u = par[u][i];
    }
  }
  if (u == v) {
    return u;
  }
  for (int i = lgn - 1; ~i; --i) {
    if (par[u][i] != par[v][i]) {
      u = par[u][i];
      v = par[v][i];
    }
  }
  return par[u][0];
}
inline void updf(int &f, int u) {
  if (dep[f] > dep[u]) {
    f = u;
  }
  return;
}
inline void dfs2(int u) {
  for (int &v : g[u]) {
    if (v != par[u][0]) {
      dfs2(v);
      updf(f[u][0], f[v][0]);
    }
  }
  return;
}
inline void M(int lg, int i, int u, int l = 1, int r = n, int k = 1) {
  if (l == r) {
    seg[lg][k] = u;
    return;
  }
  int mid = l + r >> 1, lc = k << 1, rc = (k << 1) | 1;
  if (i <= mid) {
    M(lg, i, u, l, mid, lc);
  } else {
    M(lg, i, u, mid + 1, r, rc);
  }
  seg[lg][k] = seg[lg][lc];
  updf(seg[lg][k], seg[lg][rc]);
  return;
}
inline void Q(int lg, int a, int b, int &ret, int l = 1, int r = n, int k = 1) {
  if (a <= l && r <= b) {
    updf(ret, seg[lg][k]);
    return;
  }
  int mid = l + r >> 1, lc = k << 1, rc = (k << 1) | 1;
  if (a <= mid) {
    Q(lg, a, b, ret, l, mid, lc);
  }
  if (b > mid) {
    Q(lg, a, b, ret, mid + 1, r, rc);
  }
  return;
}
inline void dfs3(int u) {
  if (u == 1) {
    for (int i = 1; i < lgn; ++i) {
      f[u][i] = f[u][0];
    }
  } else {
    for (int i = 1; i < lgn; ++i) {
      int a = dep[f[u][i - 1]], b = dep[u] - 1;
      f[u][i] = u;
      if (a <= b) {
        Q(i, a, b, f[u][i]);
      }
    }
  }
  for (int i = 0; i < lgn; ++i) {
    M(i, dep[u], f[u][i]);
  }
  for (int &v : g[u]) {
    if (v != par[u][0]) {
      dfs3(v);
    }
  }
  return;
}
int qf(int u, int dest) {
  int d = dep[dest];
  if (dep[f[u][lgn - 1]] > d) {
    return -1;
  }
  int ret = 0;
  for (int i = lgn - 1; ~i; --i) {
    if (dep[f[u][i]] > d) {
      u = f[u][i];
      ret |= (1 << i);
    }
  }
  return ret + 1;
}
int go_up(int u, int d) {
  for (int i = 0; i < d; ++i) {
    if ((d >> i) & 1) {
      u = f[u][i];
    }
  }
  return u;
}
inline int lowbit(int i) { return i & (-i); }
inline void bitM(int i, int x) {
  for (; i <= n; i += lowbit(i)) {
    fen[i] += x;
  }
  return;
}
inline int bitQ(int i) {
  int x = 0;
  for (; i; i ^= lowbit(i)) {
    x += fen[i];
  }
  return x;
}
int main(int argc, char *argv[]) {
  ;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int u;
    scanf("%d", &u);
    g[u].push_back(i);
    g[i].push_back(u);
  }
  dfs1(1, 0);
  scanf("%d", &m);
  for (int i = 1; i <= m; ++i) {
    scanf("%d%d", U + i, V + i);
    V[i + m] = U[i];
    U[i + m] = V[i];
  }
  m <<= 1;
  for (int i = 1; i <= n; ++i) {
    f[i][0] = i;
  }
  for (int i = 1; i <= m; ++i) {
    int &u = U[i], &v = V[i], fa = lca(u, v);
    updf(f[u][0], fa);
  }
  dfs2(1);
  dfs3(1);
  scanf("%d", &q);
  for (int i = 1; i <= q; ++i) {
    int a, b;
    scanf("%d%d", &a, &b);
    int c = lca(a, b);
    if (c == b) {
      swap(a, b);
    }
    if (c == a) {
      ans[i] = qf(b, a);
    } else {
      int x = qf(a, c), y = qf(b, c);
      if (!~x || !~y) {
        ans[i] = -1;
      } else {
        ans[i] = x + y;
        tag[i] = 1;
        int na = go_up(a, x - 1), nb = go_up(b, y - 1);
        int ba = dfn[na] - 1, ea = End[na], bb = dfn[nb] - 1, eb = End[nb];
        qry[q_n++] = query(ea, eb, i);
        qry[q_n++] = query(ea, bb, -i);
        qry[q_n++] = query(ba, eb, -i);
        qry[q_n++] = query(ba, bb, i);
      }
    };
  }
  sort(qry, qry + q_n, [&](query a, query b) { return a.x < b.x; });
  for (int i = 1; i <= m; ++i) {
    info[i] = query(dfn[U[i]], dfn[V[i]], i);
  }
  sort(info + 1, info + m + 1, [&](query a, query b) { return a.x < b.x; });
  for (int i = 0, j = 0; i < q_n; ++i) {
    auto &t = qry[i];
    while (j + 1 <= m && info[j + 1].x <= t.x) {
      ++j;
      bitM(info[j].y, 1);
    }
    int z = bitQ(t.y);
    if (t.i > 0) {
      res[t.i] += z;
    } else {
      res[-t.i] -= z;
    }
  }
  for (int i = 1; i <= q; ++i) {
    if (tag[i]) {
      printf("%d\n", ans[i] - (res[i] > 0));
    } else {
      printf("%d\n", ans[i]);
    }
  }
  return 0;
}