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;
#pragma comment(linker, "/STACK:102400000,102400000")
const int MAX = 210000;
const int INF = 1000000000;
const int MOD = 1000000007;
const int logN = 19;
vector<int> e[MAX];
int f[MAX][logN];
int lowerst[MAX];
int low[MAX][logN];
int deep[MAX];
int timeIn[MAX], timeOut[MAX];
int stamp = 0;
void DFS(int r, int pre) {
  f[r][0] = pre;
  deep[r] = deep[pre] + 1;
  int i, v;
  timeIn[r] = stamp++;
  for (i = 1; i < logN; i++) {
    f[r][i] = f[f[r][i - 1]][i - 1];
  }
  for (i = 0; i < e[r].size(); i++) {
    v = e[r][i];
    DFS(v, r);
  }
  timeOut[r] = stamp;
}
int tree[MAX];
int query(int t) {
  int ret = 0;
  while (t) {
    ret += tree[t];
    t -= (-t) & t;
  }
  return ret;
}
void ins(int t, int n) {
  while (t <= n) {
    tree[t]++;
    t += (-t) & t;
  }
}
bool isAncestor(int u, int v) {
  return timeIn[u] <= timeIn[v] && timeOut[u] >= timeOut[v];
}
int getLca(int u, int v) {
  if (isAncestor(u, v)) {
    return u;
  }
  if (isAncestor(v, u)) {
    return v;
  }
  int i;
  for (i = logN - 1; i >= 0; i--) {
    if (!isAncestor(f[u][i], v)) {
      u = f[u][i];
    }
  }
  return f[u][0];
}
void getLow(int r, int pre) {
  int i, v;
  low[r][0] = lowerst[r];
  for (i = 1; i < logN; i++) {
    low[r][i] = low[low[r][i - 1]][i - 1];
  }
  for (i = 0; i < e[r].size(); i++) {
    v = e[r][i];
    getLow(v, r);
  }
}
void getLowerst(int r, int pre) {
  int i, v;
  for (i = 0; i < e[r].size(); i++) {
    v = e[r][i];
    getLowerst(v, r);
    lowerst[r] = min(lowerst[r], lowerst[v]);
  }
}
int ans[MAX];
int crimb(int u, int v, int &ret) {
  int i;
  for (i = logN - 1; i >= 0; i--) {
    if (!isAncestor(low[u][i], v)) {
      ret += 1 << i;
      u = low[u][i];
    }
  }
  return u;
}
vector<int> w[MAX];
vector<pair<int, int> > q[MAX];
int roadNum[MAX];
void queryOneStep(int r, int n) {
  int i, v;
  int id;
  for (i = 0; i < q[r].size(); i++) {
    id = q[r][i].second;
    v = q[r][i].first;
    roadNum[id] = -query(timeOut[v] - 1) + query(timeIn[v] - 1);
  }
  for (i = 0; i < w[r].size(); i++) {
    ins(timeIn[w[r][i]], n);
  }
  for (i = 0; i < e[r].size(); i++) {
    queryOneStep(e[r][i], n);
  }
  for (i = 0; i < q[r].size(); i++) {
    id = q[r][i].second;
    v = q[r][i].first;
    roadNum[id] += query(timeOut[v] - 1) - query(timeIn[v] - 1);
    ans[id] -= (roadNum[id] > 0);
  }
}
bool reach(int u, int v) { return deep[low[u][logN - 1]] <= deep[v]; }
int main() {
  int i, j;
  int T = 0;
  int n = 1, m;
  cin >> n;
  for (i = 1; i <= n; i++) {
    w[i].clear();
    e[i].clear();
    lowerst[i] = i;
    q[i].clear();
    tree[i] = 0;
  }
  for (i = 2; i <= n; i++) {
    scanf("%d", &j);
    e[j].push_back(i);
  }
  deep[0] = 0;
  for (i = 0; i < logN; i++) {
    f[0][i] = 0;
  }
  lowerst[0] = 0;
  timeIn[0] = 0;
  timeOut[0] = n + 1;
  for (i = 0; i < logN; i++) {
    low[0][i] = 0;
  }
  stamp = 1;
  DFS(1, 0);
  cin >> m;
  for (i = 0; i < m; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    w[u].push_back(v);
    w[v].push_back(u);
    int lca = getLca(u, v);
    if (deep[lca] < deep[lowerst[u]]) {
      lowerst[u] = lca;
    }
    if (deep[lca] < deep[lowerst[v]]) {
      lowerst[v] = lca;
    }
  }
  getLowerst(1, 0);
  getLow(1, 0);
  int Q;
  cin >> Q;
  for (i = 0; i < Q; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    int lca = getLca(u, v);
    if (!reach(u, lca) || !reach(v, lca)) {
      ans[i] = -1;
      continue;
    }
    ans[i] = 0;
    u = crimb(u, lca, ans[i]);
    v = crimb(v, lca, ans[i]);
    if (u != lca && v != lca) {
      q[u].push_back(make_pair(v, i));
    }
    ans[i] += (u != lca) + (v != lca);
  }
  queryOneStep(1, n);
  for (i = 0; i < Q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}