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 N = 2e5 + 5, L = 20;
vector<int> v[N], up[N], w[N], mem[N];
vector<pair<int, int>> wh[N];
int tin[N], tout[N], p[N][L], lw[N][L], h[N], t[N], ans[N], sub[N];
int timer = 1;
bool bad[N];
void add(int x) {
  for (; x < N; x |= x + 1) t[x]++;
}
int que(int x) {
  int s = 0;
  for (; x >= 0; x = (x & (x + 1)) - 1) s += t[x];
  return s;
}
void dfs(int node, int anc) {
  p[node][0] = anc;
  for (int i = 1; i < L; i++) p[node][i] = p[p[node][i - 1]][i - 1];
  tin[node] = timer++;
  for (int to : v[node]) {
    dfs(to, node);
  }
  tout[node] = timer;
}
int deep(int node) {
  lw[node][0] = -1;
  for (int to : v[node]) {
    h[to] = h[node] + 1;
    int a = deep(to);
    if (a != -1 && (lw[node][0] == -1 || h[lw[node][0]] > h[a]))
      lw[node][0] = a;
  }
  for (int a : up[node]) {
    if (lw[node][0] == -1 || h[lw[node][0]] > h[a]) lw[node][0] = a;
  }
  if (h[lw[node][0]] >= h[node]) lw[node][0] = -1;
  return lw[node][0];
}
void inward(int node) {
  for (int i = 1; i < L; i++) {
    if (lw[node][i - 1] == -1)
      lw[node][i] = -1;
    else
      lw[node][i] = lw[lw[node][i - 1]][i - 1];
  }
  for (int to : v[node]) inward(to);
}
bool upper(int a, int b) { return tin[a] <= tin[b] && tout[a] >= tout[b]; }
int lca(int a, int b) {
  if (upper(a, b)) return a;
  for (int i = L - 1; i >= 0; i--) {
    if (!upper(p[a][i], b)) a = p[a][i];
  }
  return p[a][0];
}
int handle(int a, int b, int c) {
  if (a == b) return a;
  ans[c]++;
  for (int i = L - 1; i >= 0; i--) {
    if (lw[a][i] != -1 && !upper(lw[a][i], b)) {
      a = lw[a][i];
      ans[c] += (1 << i);
    }
  }
  if (lw[a][0] == -1) bad[c] = 1;
  return a;
}
void walk(int node) {
  mem[node].resize(wh[node].size());
  for (int i = 0; i < wh[node].size(); i++) {
    auto g = wh[node][i];
    mem[node][i] = que(tout[g.first] - 1) - que(tin[g.first] - 1);
  }
  for (auto g : w[node]) {
    add(tin[g]);
  }
  for (int to : v[node]) walk(to);
  for (int i = 0; i < wh[node].size(); i++) {
    auto g = wh[node][i];
    if (mem[node][i] != que(tout[g.first] - 1) - que(tin[g.first] - 1))
      sub[g.second] = 1;
  }
}
int main() {
  int n, m, q;
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    v[p - 1].push_back(i);
  }
  dfs(0, 0);
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    int x, y, l;
    scanf("%d%d", &x, &y);
    x--, y--;
    l = lca(x, y);
    if (l != x) up[x].push_back(l);
    if (l != y) up[y].push_back(l);
    if (l != x && l != y) {
      w[x].push_back(y);
      w[y].push_back(x);
    }
  }
  memset(lw, -1, sizeof(lw));
  deep(0);
  inward(0);
  scanf("%d", &q);
  for (int i = 0; i < q; i++) {
    int x, y, l;
    scanf("%d%d", &x, &y);
    x--, y--;
    l = lca(x, y);
    x = handle(x, l, i);
    y = handle(y, l, i);
    if (!bad[i] && x != l && y != l) {
      wh[x].emplace_back(y, i);
      wh[y].emplace_back(x, i);
    }
  }
  walk(0);
  for (int i = 0; i < q; i++) {
    if (bad[i])
      printf("-1\n");
    else
      printf("%d\n", ans[i] - sub[i]);
  }
  return 0;
}