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;
template <class T>
void rd(T &x) {
  x = 0;
  int f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + ch - '0', ch = getchar();
  x *= f;
}
const int maxn = 2e5 + 5;
int n, m, q, t, idx;
int dep[maxn], pre[maxn][21], low[maxn][21];
int dfn[maxn], lst[maxn], cnt[maxn];
int ans[maxn], mrk[maxn], sum[maxn];
struct node {
  int id, x, y;
  bool operator<(const node &b) const { return x == b.x ? !id : x < b.x; }
} p[maxn * 5];
struct edge {
  int v, nxt;
};
int head[maxn];
vector<edge> e;
void adde(int u, int v) {
  e.push_back((edge){v, head[u]});
  head[u] = e.size() - 1;
}
int mind(int a, int b) { return dep[a] < dep[b] ? a : b; }
void dfs1(int u, int f) {
  dfn[u] = ++idx;
  dep[u] = dep[f] + 1;
  pre[u][0] = f;
  for (int i = (1); i <= (20); ++i) pre[u][i] = pre[pre[u][i - 1]][i - 1];
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs1(v, u);
  }
  lst[u] = idx;
}
void dfs2(int u, int f) {
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs2(v, u);
    low[u][0] = mind(low[u][0], low[v][0]);
  }
}
void dfs3(int u, int f) {
  for (int i = (1); i <= (20); ++i) low[u][i] = low[low[u][i - 1]][i - 1];
  for (int i = head[u]; ~i; i = e[i].nxt) {
    int v = e[i].v;
    if (v == f) continue;
    dfs3(v, u);
  }
}
int find_under(int &u, int v) {
  if (u == v) return 0;
  int res = 0;
  for (int i = (20); i >= (0); --i)
    if (dep[v] < dep[low[u][i]]) {
      res += (1 << i);
      u = low[u][i];
    }
  if (dep[low[u][0]] > dep[v]) u = -1;
  return res;
}
int lca(int a, int b) {
  if (dep[a] > dep[b]) swap(a, b);
  for (int i = (20); i >= (0); --i)
    if (dep[a] <= dep[b] - (1 << i)) b = pre[b][i];
  if (a == b) return a;
  for (int i = (20); i >= (0); --i)
    if (pre[a][i] != pre[b][i]) a = pre[a][i], b = pre[b][i];
  return pre[a][0];
}
void insert(int x) {
  x++;
  for (; x < maxn; x += x & -x) sum[x]++;
}
int query(int x) {
  x++;
  int y = 0;
  for (; x; x -= x & -x) y += sum[x];
  return y;
}
void sol() {
  rd(q);
  for (int i = (1); i <= (q); ++i) {
    int u, v;
    rd(u), rd(v);
    int l = lca(u, v);
    ans[i] += find_under(u, l);
    ans[i] += find_under(v, l);
    if (u == -1 || v == -1) {
      ans[i] = -1;
      continue;
    } else if (u == l || v == l) {
      ans[i]++;
      continue;
    }
    mrk[i] = 1;
    if (dfn[u] > dfn[v]) swap(u, v);
    p[++t] = (node){i, lst[u], lst[v]};
    p[++t] = (node){-i, dfn[u] - 1, lst[v]};
    p[++t] = (node){-i, lst[u], dfn[v] - 1};
    p[++t] = (node){i, dfn[u] - 1, dfn[v] - 1};
  }
  sort(p + 1, p + t + 1);
  for (int i = (1); i <= (t); ++i) {
    int id = p[i].id, x = p[i].x, y = p[i].y;
    if (id == 0)
      insert(p[i].y);
    else {
      if (id > 0)
        cnt[id] += query(p[i].y);
      else
        cnt[-id] -= query(p[i].y);
    }
  }
  for (int i = (1); i <= (q); ++i) {
    if (!mrk[i])
      printf("%d\n", ans[i]);
    else {
      if (cnt[i])
        printf("%d\n", ans[i] + 1);
      else
        printf("%d\n", ans[i] + 2);
    }
  }
}
int main() {
  memset(head, -1, sizeof(head));
  rd(n);
  for (int i = (2); i <= (n); ++i) {
    int u;
    rd(u);
    adde(u, i), adde(i, u);
  }
  dfs1(1, 0);
  dep[0] = n;
  rd(m);
  for (int i = (1); i <= (m); ++i) {
    int u, v;
    rd(u), rd(v);
    int l = lca(u, v);
    if (u != l) low[u][0] = mind(low[u][0], l);
    if (v != l) low[v][0] = mind(low[v][0], l);
    if (dfn[u] > dfn[v]) swap(u, v);
    p[++t] = (node){0, dfn[u], dfn[v]};
  }
  dfs2(1, 0);
  dfs3(1, 0);
  sol();
  return 0;
}