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;
int ls[401000 * 20], rs[401000 * 20], L[401000], R[401000], cnt, trcnt,
    rt[401000], root[401000], fa[401000][20], g[401000][20], dep[401000], size,
    g1[401000];
int siz[401000 * 20], tag[401000], n, m, o, p, q, i;
struct node {
  int to, next;
} e[401000];
pair<int, int> a[401000];
void add(int o, int p) {
  e[++size].to = p;
  e[size].next = g1[o];
  g1[o] = size;
}
void dfs1(int x) {
  L[x] = ++cnt;
  for (int i = 1; i <= 18; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int k = g1[x]; k; k = e[k].next) {
    int y = e[k].to;
    if (y != fa[x][0]) {
      dep[y] = dep[x] + 1;
      fa[y][0] = x;
      dfs1(y);
    }
  }
  R[x] = cnt;
}
void dfs2(int x) {
  int ret = tag[x];
  for (int k = g1[x]; k; k = e[k].next) {
    int y = e[k].to;
    if (y != fa[x][0]) {
      dfs2(y);
      if (dep[g[y][0]] < dep[ret]) ret = g[y][0];
    }
  }
  g[x][0] = ret;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int d = (dep[x] - dep[y]);
  for (int i = 0; i <= 18; i++)
    if (d & (1 << i)) x = fa[x][i];
  if (x == y) return x;
  for (int i = 18; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void insert(int old, int &rt, int l, int r, int x) {
  rt = ++trcnt;
  ls[rt] = ls[old], rs[rt] = rs[old];
  siz[rt] = siz[old];
  if (l == r) {
    siz[rt]++;
    return;
  }
  if (x <= ((l + r) / 2))
    insert(ls[old], ls[rt], l, ((l + r) / 2), x);
  else
    insert(rs[old], rs[rt], ((l + r) / 2) + 1, r, x);
  siz[rt] = siz[ls[rt]] + siz[rs[rt]];
}
int query(int old, int rt, int l, int r, int x, int y) {
  if (x <= l && r <= y) return siz[rt] - siz[old];
  int ret = 0;
  if (x <= ((l + r) / 2)) ret += query(ls[old], ls[rt], l, ((l + r) / 2), x, y);
  if (y >= ((l + r) / 2) + 1)
    ret += query(rs[old], rs[rt], ((l + r) / 2) + 1, r, x, y);
  return ret;
}
bool check(int x, int y) {
  if (L[x] > L[y]) swap(x, y);
  return query(root[L[x] - 1], root[R[x]], 1, n, L[y], R[y]) > 0;
}
int main() {
  scanf("%d", &n);
  for (i = 2; i <= n; i++) {
    scanf("%d", &o);
    add(o, i);
    add(i, o);
  }
  dfs1(1);
  for (i = 1; i <= n; i++) tag[i] = i;
  scanf("%d", &m);
  for (i = 1; i <= m; i++) {
    scanf("%d %d", &o, &p);
    if (L[o] > L[p]) swap(o, p);
    int l = lca(o, p);
    if (dep[l] < dep[tag[o]]) tag[o] = l;
    if (dep[l] < dep[tag[p]]) tag[p] = l;
    a[i] = make_pair(L[o], L[p]);
  }
  dfs2(1);
  for (i = 1; i <= 18; i++)
    for (int x = 1; x <= n; x++) g[x][i] = g[g[x][i - 1]][i - 1];
  sort(a + 1, a + 1 + m);
  for (i = 1; i <= m; i++) {
    insert(rt[i - 1], rt[i], 1, n, a[i].second);
    root[a[i].first] = rt[i];
  }
  for (i = 1; i <= n; i++)
    if (root[i] == 0) root[i] = root[i - 1];
  scanf("%d", &q);
  while (q--) {
    scanf("%d %d", &o, &p);
    int ans = 0;
    int l = lca(o, p);
    for (i = 18; i >= 0; i--)
      if (dep[g[o][i]] > dep[l]) ans += (1 << i), o = g[o][i];
    for (i = 18; i >= 0; i--)
      if (dep[g[p][i]] > dep[l]) ans += (1 << i), p = g[p][i];
    if (L[o] > L[p]) swap(o, p);
    if (R[o] >= R[p]) {
      if (dep[g[p][0]] <= dep[o])
        printf("%d\n", ans + 1);
      else
        printf("-1\n");
      continue;
    }
    if (g[o][0] == o || g[p][0] == p) {
      printf("-1\n");
      continue;
    }
    if (check(o, p))
      printf("%d\n", ans + 1);
    else
      printf("%d\n", ans + 2);
  }
}