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 MAXN = 300005;
struct edge {
  int to, next;
} e[MAXN * 2];
int head[MAXN], edgetot;
int in[MAXN], out[MAXN], timetot, vis[MAXN];
int f[MAXN][30], dep[MAXN], nf[MAXN][30];
struct node {
  int x, y, k, id;
} d[MAXN * 5];
int ask, a[MAXN], b[MAXN];
int N, M, Q;
int tree[MAXN];
int bin[MAXN], ans[MAXN], ANS[MAXN];
int lowbit(int x) { return x & (-x); }
void update(int x, int v) {
  for (int i = x; i <= N; i += lowbit(i)) tree[i] += v;
}
int query(int x) {
  int tot = 0;
  for (int i = x; i > 0; i -= lowbit(i)) {
    tot += tree[i];
  }
  return tot;
}
void add(int x, int y) {
  e[++edgetot].to = y;
  e[edgetot].next = head[x];
  head[x] = edgetot;
}
void first_dfs(int fa, int x, int deep) {
  if (vis[x] == 1) return;
  vis[x] = 1;
  dep[x] = deep;
  f[x][0] = fa;
  in[x] = ++timetot;
  for (int j = 1; (1 << j) <= dep[x]; j++) f[x][j] = f[f[x][j - 1]][j - 1];
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    first_dfs(x, v, deep + 1);
  }
  out[x] = timetot;
}
int lca(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  for (int j = 20; j >= 0; j--) {
    if (dep[f[x][j]] >= dep[y]) x = f[x][j];
  }
  if (x == y) return x;
  for (int j = 20; j >= 0; j--) {
    if (f[x][j] != f[y][j]) {
      x = f[x][j];
      y = f[y][j];
    }
  }
  return f[x][0];
}
void second_dfs(int fa, int x) {
  for (int i = head[x]; i; i = e[i].next) {
    int v = e[i].to;
    if (v != fa) {
      second_dfs(x, v);
      if (!nf[x][0] || (nf[v][0] && dep[nf[v][0]] < dep[nf[x][0]]))
        nf[x][0] = nf[v][0];
    }
  }
}
bool cmp(node a, node b) {
  if (a.x == b.x) return a.id < b.id;
  return a.x < b.x;
}
void test() {
  cout << "---------dep----------" << endl;
  for (int i = 1; i <= N; i++) {
    cout << i << ":" << dep[i] << endl;
  }
  cout << "----------lca----------" << endl;
  for (int i = 1; i <= N; i++)
    for (int j = 1; j <= N; j++)
      cout << i << " " << j << ":" << lca(i, j) << endl;
  cout << "----------in/out------------" << endl;
  for (int i = 1; i <= N; i++) {
    cout << i << ":" << in[i] << " " << out[i] << endl;
  }
  cout << "----------nf------------" << endl;
  for (int i = 1; i <= N; i++) {
    for (int j = 0; j <= 20; j++) {
      cout << i << " " << j << ":" << nf[i][j] << endl;
    }
  }
}
int main() {
  scanf("%d", &N);
  for (int i = 2; i <= N; i++) {
    int tmp;
    scanf("%d", &tmp);
    add(tmp, i);
    add(i, tmp);
  }
  first_dfs(0, 1, 1);
  scanf("%d", &M);
  for (int i = 1; i <= M; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int t = lca(a, b);
    if (in[a] > in[b]) swap(a, b);
    if (!nf[a][0] || dep[t] < dep[nf[a][0]]) nf[a][0] = t;
    if (!nf[b][0] || dep[t] < dep[nf[b][0]]) nf[b][0] = t;
    d[++ask] = (node){in[a], in[b], 1, 0};
  }
  second_dfs(0, 1);
  for (int i = 1; i <= N; i++)
    if (nf[i][0] == i) nf[i][0] = 0;
  for (int j = 1; j <= 20; j++) {
    for (int i = 1; i <= N; i++) {
      nf[i][j] = nf[nf[i][j - 1]][j - 1];
    }
  }
  scanf("%d", &Q);
  bin[0] = 1;
  for (int i = 1; i <= 20; i++) bin[i] = 2 * bin[i - 1];
  for (int i = 1; i <= Q; i++) {
    int a, b;
    scanf("%d%d", &a, &b);
    int t = lca(a, b);
    if (in[a] > in[b]) swap(a, b);
    for (int j = 20; j >= 0; j--)
      if (nf[a][j] && dep[nf[a][j]] > dep[t]) a = nf[a][j], ans[i] += bin[j];
    for (int j = 20; j >= 0; j--)
      if (nf[b][j] && dep[nf[b][j]] > dep[t]) b = nf[b][j], ans[i] += bin[j];
    if ((!nf[a][0] && a != t) || (!nf[b][0] && b != t)) {
      ans[i] = -1;
      continue;
    }
    if (a == t || b == t)
      ans[i]++;
    else {
      ans[i] += 2;
      d[++ask] = (node){in[a] - 1, in[b] - 1, 1, i};
      d[++ask] = (node){in[a] - 1, out[b], -1, i};
      d[++ask] = (node){out[a], in[b] - 1, -1, i};
      d[++ask] = (node){out[a], out[b], 1, i};
    }
  }
  sort(d + 1, d + ask + 1, cmp);
  for (int i = 1; i <= ask; i++) {
    if (!d[i].id)
      update(d[i].y, d[i].k);
    else {
      ANS[d[i].id] += d[i].k * query(d[i].y);
    }
  }
  for (int i = 1; i <= Q; i++) printf("%d\n", ans[i] - (ANS[i] > 0));
  return 0;
}