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 = 200100;
const int LOG = 19;
vector<int> g[N];
vector<int> G[N];
int h[N];
int par[N][LOG];
int bigPar[N][LOG];
vector<pair<int, int>> busForLCA[N];
vector<int> queryForLCA[N];
int query[N][2];
int ans[N];
int ans2[N];
int n, m;
pair<int, int> ord[N];
int ordSz;
bool bad[N];
int col[N];
int t[N][2];
int sz[N];
int fenv[N];
int T;
void addFenv(int p) {
  for (; p <= T; p |= p + 1) fenv[p]++;
}
int getFenv(int r) {
  int res = 0;
  for (; r >= 0; r = (r & (r + 1)) - 1) res += fenv[r];
  return res;
}
int getSum(int l, int r) { return getFenv(r - 1) - getFenv(l - 1); }
int up(int v, int dh) {
  for (int k = LOG - 1; k >= 0; k--) {
    if (dh < (1 << k)) continue;
    dh -= 1 << k;
    v = par[v][k];
  }
  return v;
}
int LCA(int v, int u) {
  if (h[v] > h[u]) swap(v, u);
  u = up(u, h[u] - h[v]);
  if (v == u) return v;
  for (int k = LOG - 1; k >= 0; k--) {
    if (par[v][k] != par[u][k]) {
      v = par[v][k];
      u = par[u][k];
    }
  }
  return par[v][0];
}
void dfs(int v) {
  for (int u : G[v]) {
    h[u] = h[v] + 1;
    par[u][0] = v;
    for (int k = 0; k < LOG - 1; k++) {
      int w = par[u][k];
      if (w != -1) par[u][k + 1] = par[w][k];
    }
    dfs(u);
  }
}
void markBest(int v, int w) {
  if (h[bigPar[v][0]] <= h[w]) return;
  bigPar[v][0] = w;
  markBest(par[v][0], w);
}
void solveLCA(int w) {
  for (int id : queryForLCA[w]) {
    int v = query[id][0], u = query[id][1];
    if (u == w) swap(v, u);
    if (v == w) {
      int res = 0;
      for (int k = LOG - 1; k >= 0; k--) {
        if (h[bigPar[u][k]] > h[v]) {
          res += 1 << k;
          u = bigPar[u][k];
        }
      }
      res++;
      u = bigPar[u][0];
      if (h[u] > h[v]) {
        ans[id] = -1;
        query[id][0] = query[id][1] = -1;
      } else {
        ans[id] = res;
        query[id][0] = query[id][1] = -1;
      }
      continue;
    }
    int res = 0;
    for (int k = LOG - 1; k >= 0; k--) {
      if (h[bigPar[v][k]] > h[w]) {
        res += 1 << k;
        v = bigPar[v][k];
      }
      if (h[bigPar[u][k]] > h[w]) {
        res += 1 << k;
        u = bigPar[u][k];
      }
    }
    if (h[bigPar[v][0]] > h[w] || h[bigPar[u][0]] > h[w]) {
      ans[id] = -1;
      query[id][0] = query[id][1] = -1;
    } else {
      ans[id] = res + 2;
      query[id][0] = v;
      query[id][1] = u;
    }
  }
}
void dfs2(int v, int p) {
  sz[v] = 1;
  for (int u : g[v]) {
    if (u == p || bad[u]) continue;
    dfs2(u, v);
    sz[v] += sz[u];
  }
}
int findCentroid(int v) {
  dfs2(v, -1);
  int S = sz[v];
  while (true) {
    int w = v;
    for (int u : g[v]) {
      if (bad[u] || sz[u] > sz[v]) continue;
      if (2 * sz[u] >= S) {
        v = u;
      }
    }
    if (v == w) break;
  }
  return v;
}
void dfs3(int v, int p, int c) {
  col[v] = c;
  t[v][0] = T++;
  for (int u : g[v]) {
    if (bad[u] || u == p) continue;
    int nc = c;
    if (p == -1) nc = u;
    dfs3(u, v, nc);
  }
  t[v][1] = T;
}
struct Event {
  int type;
  int x;
  int y1, y2;
  int id;
  Event() : type(), x(), y1(), y2(), id() {}
  Event(int _type, int _x, int _y1, int _y2, int _id)
      : type(_type), x(_x), y1(_y1), y2(_y2), id(_id) {}
  bool operator<(const Event &e) const {
    if (x != e.x) return x < e.x;
    return type < e.type;
  }
};
Event ev[6 * N];
int evSz;
void doEvents() {
  sort(ev, ev + evSz);
  for (int i = 0; i <= T; i++) fenv[i] = 0;
  for (int i = 0; i < evSz; i++) {
    Event e = ev[i];
    if (e.type == 0) {
      addFenv(e.y1);
    } else {
      ans2[e.id] += getSum(e.y1, e.y2) * e.type;
    }
  }
}
void solveCentroid(int v, vector<pair<int, int>> buses, vector<int> queries) {
  if (buses.empty() || queries.empty()) return;
  v = findCentroid(v);
  T = 0;
  bad[v] = 1;
  dfs3(v, -1, v);
  evSz = 0;
  for (pair<int, int> z : buses) {
    int u = z.first, w = z.second;
    if (col[u] == col[w]) continue;
    u = t[u][0];
    w = t[w][0];
    ev[evSz++] = Event(0, u, u, u, -1);
    ev[evSz++] = Event(0, u, w, w, -1);
    ev[evSz++] = Event(0, w, u, u, -1);
    ev[evSz++] = Event(0, w, w, w, -1);
  }
  for (int id : queries) {
    int u = query[id][0], w = query[id][1];
    ev[evSz++] = Event(-1, t[u][0], t[w][0], t[w][1], id);
    ev[evSz++] = Event(1, t[u][1] - 1, t[w][0], t[w][1], id);
  }
  doEvents();
  map<int, vector<pair<int, int>>> mapBuses;
  map<int, vector<int>> mapQ;
  for (pair<int, int> z : buses) {
    int u = z.first, w = z.second;
    if (col[u] != col[w]) continue;
    mapBuses[col[u]].push_back(z);
  }
  for (int id : queries) {
    int u = query[id][0], w = query[id][1];
    if (col[u] != col[w]) continue;
    mapQ[col[u]].push_back(id);
  }
  for (int u : g[v]) {
    if (bad[u]) continue;
    solveCentroid(u, mapBuses[u], mapQ[u]);
  }
}
int main() {
  scanf("%d", &n);
  for (int i = 1; i < n; i++) {
    int p;
    scanf("%d", &p);
    p--;
    G[p].push_back(i);
    g[p].push_back(i);
    g[i].push_back(p);
  }
  for (int i = 0; i < n; i++)
    for (int j = 0; j < LOG; j++) par[i][j] = -1;
  dfs(0);
  scanf("%d", &m);
  while (m--) {
    int v, u;
    scanf("%d%d", &v, &u);
    v--;
    u--;
    int w = LCA(v, u);
    busForLCA[w].push_back(make_pair(v, u));
  }
  for (int i = 0; i < n; i++) ord[i] = make_pair(h[i], i);
  sort(ord, ord + n);
  for (int v = 0; v < n; v++)
    for (int k = 0; k < LOG; k++) bigPar[v][k] = v;
  for (int i = 0; i < n; i++) {
    int v = ord[i].second;
    for (pair<int, int> t : busForLCA[v]) {
      markBest(t.first, v);
      markBest(t.second, v);
    }
  }
  for (int i = 0; i < n; i++) {
    int v = ord[i].second;
    for (int k = 0; k < LOG - 1; k++)
      bigPar[v][k + 1] = bigPar[bigPar[v][k]][k];
  }
  scanf("%d", &m);
  for (int i = 0; i < m; i++) {
    scanf("%d%d", &query[i][0], &query[i][1]);
    query[i][0]--;
    query[i][1]--;
    int w = LCA(query[i][0], query[i][1]);
    queryForLCA[w].push_back(i);
  }
  for (int v = 0; v < n; v++) solveLCA(v);
  vector<pair<int, int>> buses;
  vector<int> queries;
  for (int v = 0; v < n; v++)
    for (pair<int, int> t : busForLCA[v]) buses.push_back(t);
  for (int i = 0; i < m; i++) {
    if (query[i][0] == -1) continue;
    queries.push_back(i);
  }
  solveCentroid(0, buses, queries);
  for (int i = 0; i < m; i++) {
    if (ans2[i] > 0) ans[i]--;
    printf("%d\n", ans[i]);
  }
  return 0;
}