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;
inline void read(int &x) {
  int v = 0, f = 1;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void read(long long &x) {
  long long v = 0ll, f = 1ll;
  char c = getchar();
  while (!isdigit(c) && c != '-') c = getchar();
  if (c == '-')
    f = -1;
  else
    v = (c & 15);
  while (isdigit(c = getchar())) v = (v << 1) + (v << 3) + (c & 15);
  x = v * f;
}
inline void readc(char &x) {
  char c;
  while (((c = getchar()) == ' ') || c == '\n')
    ;
  x = c;
}
int n, m, q, i, j, f[200005][19], dep[200005], fa[200005][19], first[200005],
    ed[200005], ti, px[200005], py[200005], ans[200005], ss[200005];
vector<int> e[200005];
int gtmx(int x, int y) {
  if (!x) return y;
  if (!y) return x;
  return dep[x] < dep[y] ? x : y;
}
void dfs1(int x, int fa) {
  first[x] = ++ti;
  ::fa[x][0] = fa;
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)
    if (*it != fa) {
      dep[*it] = dep[x] + 1;
      dfs1(*it, x);
    }
  ed[x] = ti;
}
void dfs2(int x, int fa) {
  for (__typeof((e[x]).begin()) it = (e[x]).begin(); it != (e[x]).end(); it++)
    if (*it != fa) {
      dfs2(*it, x);
      f[x][0] = gtmx(f[x][0], f[*it][0]);
    }
  if (dep[f[x][0]] >= dep[x]) f[x][0] = 0;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int t = dep[x] - dep[y], i;
  for ((i) = (18); (i) >= (0); (i)--)
    if ((t >> i) & 1) x = fa[x][i];
  if (x == y) return x;
  for ((i) = (18); (i) >= (0); (i)--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
struct tt {
  int op, x, y, z;
};
vector<tt> v;
bool cmp(tt x, tt y) {
  if (x.x == y.x) return x.op < y.op;
  return x.x < y.x;
}
int s[200005];
void add(int x, int y) {
  while (x <= n) {
    s[x] += y;
    x += (x & -x);
  }
}
int qry(int x) {
  int ss = 0;
  while (x) {
    ss += s[x];
    x -= (x & -x);
  }
  return ss;
}
int main() {
  read(n);
  for ((i) = (2); (i) <= (n); (i)++) {
    int x;
    read(x);
    e[x].push_back(i);
  }
  dfs1(1, 0);
  for (((j)) = (1); ((j)) <= ((18)); ((j))++)
    for (((i)) = (1); ((i)) <= ((n)); ((i))++)
      fa[i][j] = fa[fa[i][j - 1]][j - 1];
  read(m);
  for (((i)) = (1); ((i)) <= ((m)); ((i))++) {
    int x, y;
    read(x);
    read(y);
    v.push_back((tt){0, first[x], first[y], 1});
    v.push_back((tt){0, first[y], first[x], 1});
    int z = lca(x, y);
    f[x][0] = gtmx(f[x][0], z);
    f[y][0] = gtmx(f[y][0], z);
  }
  dfs2(1, 0);
  for (((j)) = (1); ((j)) <= ((18)); ((j))++)
    for (((i)) = (1); ((i)) <= ((n)); ((i))++) f[i][j] = f[f[i][j - 1]][j - 1];
  read(q);
  for (((i)) = (1); ((i)) <= ((q)); ((i))++) {
    int x, y, j;
    read(x);
    read(y);
    int z = lca(x, y);
    for ((j) = (18); (j) >= (0); (j)--)
      if (dep[f[x][j]] > dep[z]) {
        x = f[x][j];
        ans[i] += (1 << j);
      }
    for ((j) = (18); (j) >= (0); (j)--)
      if (dep[f[y][j]] > dep[z]) {
        y = f[y][j];
        ans[i] += (1 << j);
      }
    if (x != z && (!f[x][0] || dep[f[x][0]] > dep[z])) {
      ans[i] = -3;
      continue;
    }
    if (y != z && (!f[y][0] || dep[f[y][0]] > dep[z])) {
      ans[i] = -3;
      continue;
    }
    if (first[x] <= first[y] && ed[y] <= ed[x]) {
      ss[i] = 1;
      continue;
    }
    if (first[y] <= first[x] && ed[x] <= ed[y]) {
      ss[i] = 1;
      continue;
    }
    v.push_back((tt){i, ed[x], ed[y], 1});
    v.push_back((tt){i, ed[x], first[y] - 1, -1});
    v.push_back((tt){i, first[x] - 1, ed[y], -1});
    v.push_back((tt){i, first[x] - 1, first[y] - 1, 1});
  }
  sort(v.begin(), v.end(), cmp);
  for (((i)) = (0); ((i)) <= (((int)(v.size())) - 1); ((i))++) {
    if (!v[i].op)
      add(v[i].y, v[i].z);
    else
      ss[v[i].op] += v[i].z * qry(v[i].y);
  }
  for (((i)) = (1); ((i)) <= ((q)); ((i))++) {
    printf("%d\n", ans[i] + 2 - !!ss[i]);
  }
  return 0;
}