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 __i__, __j__;
class _Debug {
 public:
  template <typename T>
  _Debug& operator,(T val) {
    cout << val << endl;
    return *this;
  }
};
vector<int> adjList[200000];
int a[200000], b[200000], uu[200000], vv[200000];
int parent[200000][18], best[200000][18], depth[200000];
int disc[200000], fin[200000], order[200000], num = 0;
int doDFS(int u, int p, int d) {
  int i;
  parent[u][0] = p, depth[u] = d;
  disc[u] = num++, order[num - 1] = u;
  for (i = 0; i < adjList[u].size(); i++) {
    int v = adjList[u][i];
    doDFS(v, u, d + 1);
  }
  fin[u] = num;
  return 0;
}
int logn;
int depth2[200000], root[200000];
int ans[200000], occ[200000];
struct event {
  int x, y1, y2, t, i;
};
bool comp(event a, event b) {
  if (a.x == b.x) return a.t > b.t;
  return a.x < b.x;
}
vector<event> events;
int bit[200001];
int main() {
  int i;
  int n, m, q, p;
  scanf("%d", &n);
  for (i = 1; i < n; i++) scanf("%d", &p), adjList[p - 1].push_back(i);
  scanf("%d", &m);
  for (i = 0; i < m; i++) scanf("%d %d", &a[i], &b[i]), a[i]--, b[i]--;
  scanf("%d", &q);
  for (i = 0; i < q; i++) scanf("%d %d", &uu[i], &vv[i]), uu[i]--, vv[i]--;
  doDFS(0, -1, 0);
  int j;
  for (i = 1; (1 << i) < n; i++) {
    for (j = 0; j < n; j++) {
      if (parent[j][i - 1] != -1)
        parent[j][i] = parent[parent[j][i - 1]][i - 1];
      else
        parent[j][i] = -1;
    }
  }
  logn = i;
  memset(best, -1, sizeof(best));
  for (i = 0; i < m; i++) {
    int u = a[i], v = b[i];
    if (depth[u] < depth[v]) swap(u, v);
    for (j = logn - 1; j >= 0; j--) {
      if ((parent[u][j] != -1) && (depth[parent[u][j]] >= depth[v]))
        u = parent[u][j];
    }
    if (u != v) {
      for (j = logn - 1; j >= 0; j--) {
        if (parent[u][j] != parent[v][j]) u = parent[u][j], v = parent[v][j];
      }
      u = parent[u][0];
    }
    int lca = u;
    u = a[i], v = b[i];
    if (depth[u] < depth[v]) swap(u, v);
    for (j = logn - 1; j >= 0; j--) {
      if ((parent[u][j] != -1) && (depth[parent[u][j]] >= depth[v])) {
        if ((best[u][j] == -1) || (depth[lca] <= depth[best[u][j]]))
          best[u][j] = lca;
        u = parent[u][j];
      }
    }
    if (u != v) {
      for (j = logn - 1; j >= 0; j--) {
        if (parent[u][j] != parent[v][j]) {
          if ((best[u][j] == -1) || (depth[lca] <= depth[best[u][j]]))
            best[u][j] = lca;
          if ((best[v][j] == -1) || (depth[lca] <= depth[best[v][j]]))
            best[v][j] = lca;
          u = parent[u][j], v = parent[v][j];
        }
      }
      if ((best[u][0] == -1) || (depth[lca] <= depth[best[u][0]]))
        best[u][0] = lca;
      if ((best[v][0] == -1) || (depth[lca] <= depth[best[v][0]]))
        best[v][0] = lca;
    }
  }
  for (i = logn - 1; i >= 1; i--) {
    for (j = 0; j < n; j++) {
      if (best[j][i] != -1) {
        if ((best[j][i - 1] == -1) ||
            (depth[best[j][i]] <= depth[best[j][i - 1]]))
          best[j][i - 1] = best[j][i];
        int u = parent[j][i - 1];
        if ((best[u][i - 1] == -1) ||
            (depth[best[j][i]] <= depth[best[u][i - 1]]))
          best[u][i - 1] = best[j][i];
      }
    }
  }
  for (i = 1; i < logn; i++) {
    for (j = 0; j < n; j++) {
      if (best[j][i - 1] != -1)
        best[j][i] = best[best[j][i - 1]][i - 1];
      else
        best[j][i] = -1;
    }
  }
  for (i = 0; i < n; i++) {
    int u = order[i];
    if (best[u][0] == -1)
      depth2[u] = 0, root[u] = u;
    else
      depth2[u] = depth2[best[u][0]] + 1, root[u] = root[best[u][0]];
  }
  for (i = 0; i < q; i++) {
    int u = uu[i], v = vv[i];
    if (root[u] != root[v]) {
      ans[i] = -1;
      continue;
    }
    if (depth[u] < depth[v]) swap(u, v);
    for (j = logn - 1; j >= 0; j--) {
      if ((parent[u][j] != -1) && (depth[parent[u][j]] >= depth[v]))
        u = parent[u][j];
    }
    if (u != v) {
      for (j = logn - 1; j >= 0; j--) {
        if (parent[u][j] != parent[v][j]) u = parent[u][j], v = parent[v][j];
      }
      u = parent[u][0];
    }
    int lca = u;
    u = uu[i], v = vv[i];
    for (j = logn - 1; j >= 0; j--) {
      if ((best[u][j] != -1) && (depth[best[u][j]] > depth[lca]))
        u = best[u][j];
    }
    for (j = logn - 1; j >= 0; j--) {
      if ((best[v][j] != -1) && (depth[best[v][j]] > depth[lca]))
        v = best[v][j];
    }
    if (u != lca) u = best[u][0];
    if (v != lca) v = best[v][0];
    int x = depth2[uu[i]] - depth2[u], y = depth2[vv[i]] - depth2[v];
    ans[i] = x + y;
    if ((x > 0) && (y > 0)) {
      x--, y--;
      u = uu[i], v = vv[i];
      for (j = logn - 1; j >= 0; j--) {
        if ((1 << j) <= x) u = best[u][j], x -= (1 << j);
      }
      for (j = logn - 1; j >= 0; j--) {
        if ((1 << j) <= y) v = best[v][j], y -= (1 << j);
      }
      if (depth[u] > depth[v]) swap(u, v);
      if ((disc[v] >= disc[u]) && (disc[v] < fin[u])) {
        events.push_back((event){disc[v], 0, disc[u], 1, i});
        events.push_back((event){disc[v], fin[u], n - 1, 1, i});
        events.push_back((event){fin[v] - 1, 0, disc[u], -1, i});
        events.push_back((event){fin[v] - 1, fin[u], n - 1, -1, i});
      } else {
        events.push_back((event){disc[u], disc[v], fin[v] - 1, 1, i});
        events.push_back((event){fin[u] - 1, disc[v], fin[v] - 1, -1, i});
      }
    }
  }
  for (i = 0; i < m; i++) {
    events.push_back((event){disc[a[i]], disc[b[i]], disc[b[i]], 0, -1});
    events.push_back((event){disc[b[i]], disc[a[i]], disc[a[i]], 0, -1});
  }
  sort(events.begin(), events.end(), comp);
  for (i = 0; i < events.size(); i++) {
    if (events[i].t == 0) {
      for (j = events[i].y1 + 1; j <= n; j += j & (-j)) bit[j]++;
    } else {
      for (j = events[i].y2 + 1; j > 0; j -= j & (-j))
        occ[events[i].i] -= events[i].t * bit[j];
      for (j = events[i].y1; j > 0; j -= j & (-j))
        occ[events[i].i] += events[i].t * bit[j];
    }
  }
  for (i = 0; i < q; i++) {
    if (occ[i] > 0) ans[i]--;
    printf("%d\n", ans[i]);
  }
  return 0;
}