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 las[501000], nxt[501000], to[501000], n, f[501000 * 3][18], e[19],
    up[501000], dfn[501000], low[501000], g[501000 * 3][18], ans[501000],
    b[501000], tot, deep[501000], m, q, t[501000];
struct node {
  int x, y, y2, z;
} a[501000 * 2];
bool cnt(node a, node b) {
  return a.x < b.x || (a.x == b.x && a.z == 0 && b.z != 0);
}
void putin(int x, int y) {
  nxt[++tot] = las[x];
  las[x] = tot;
  to[tot] = y;
}
void dg(int x) {
  dfn[x] = ++tot;
  for (int i = las[x]; i; i = nxt[i]) {
    int y = to[i];
    deep[y] = deep[x] + 1;
    f[y][0] = x;
    dg(y);
  }
  low[x] = tot;
}
void dg1(int x) {
  for (int i = las[x]; i; i = nxt[i]) {
    int y = to[i];
    dg1(y);
    if (deep[up[y]] < deep[up[x]]) up[x] = up[y];
  }
  g[x][0] = up[x];
}
int lca(int x, int y) {
  if (deep[x] < deep[y]) swap(x, y);
  for (int i = 17; i >= 0; i--)
    if (deep[f[x][i]] >= deep[y]) x = f[x][i];
  for (int i = 17; i >= 0; i--)
    if (f[x][i] != f[y][i]) x = f[x][i], y = f[y][i];
  if (x != y) x = f[x][0];
  return x;
}
int go_up(int &x, int y) {
  int ans = 0;
  for (int i = 17; i >= 0; i--)
    if (deep[g[x][i]] > deep[y]) x = g[x][i], ans += e[i];
  return ans;
}
void ptin(int x, int y) {
  tot++;
  a[tot].x = x;
  a[tot].y = y;
  a[tot].z = 0;
}
int lowbit(int x) { return x & (-x); }
void ins(int x) {
  for (; x <= n; x += lowbit(x)) t[x]++;
}
int get(int x) {
  int ans = 0;
  for (; x; x -= lowbit(x)) ans += t[x];
  return ans;
}
int main() {
  e[0] = 1;
  for (int i = 1; i <= 18; i++) e[i] = e[i - 1] * 2;
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) up[i] = i;
  for (int i = 2; i <= n; i++) {
    int x;
    scanf("%d", &x);
    putin(x, i);
  }
  tot = 0;
  deep[1] = 1;
  dg(1);
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++) f[i][j] = f[f[i][j - 1]][j - 1];
  scanf("%d", &m);
  tot = 0;
  for (int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int z = lca(x, y);
    if (deep[z] < deep[up[x]]) up[x] = z;
    if (deep[z] < deep[up[y]]) up[y] = z;
    ptin(dfn[x], dfn[y]);
    ptin(dfn[y], dfn[x]);
  }
  dg1(1);
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++) g[i][j] = g[g[i][j - 1]][j - 1];
  scanf("%d", &q);
  for (int i = 1; i <= q; i++) {
    int x, y;
    scanf("%d%d", &x, &y);
    int z = lca(x, y);
    ans[i] = go_up(x, z) + go_up(y, z);
    if (deep[up[x]] > deep[z] || deep[up[y]] > deep[z]) ans[i] = -1;
    if ((z == x || z == y) && ans[i] != -1)
      b[i] = -10000, ans[i]++;
    else {
      tot++;
      a[tot].x = dfn[x] - 1, a[tot].y = dfn[y], a[tot].y2 = low[y],
      a[tot].z = -i;
      tot++;
      a[tot].x = low[x], a[tot].y = dfn[y], a[tot].y2 = low[y], a[tot].z = i;
    }
    if (x == y) ans[i] = 0;
  }
  sort(a + 1, a + tot + 1, cnt);
  int j = 1;
  for (int i = 0; i <= n; i++) {
    for (; a[j].x == i; j++) {
      if (a[j].z == 0) ins(a[j].y);
      if (a[j].z < 0) b[-a[j].z] -= get(a[j].y2) - get(a[j].y - 1);
      if (a[j].z > 0) b[a[j].z] += get(a[j].y2) - get(a[j].y - 1);
    }
  }
  for (int i = 1; i <= q; i++) {
    if (ans[i] == -1)
      printf("-1\n");
    else if (b[i] < 0)
      printf("%d\n", ans[i]);
    else
      printf("%d\n", ans[i] + (b[i] > 0 ? 1 : 2));
  }
}