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 + 10;
const int L = 20;
struct node {
  int nxt, to;
} bian[2 * N];
struct ques {
  int to, id, lca;
  int has;
  int fir;
};
int n, m, Q;
int que[N][2];
int hd[N], cnt;
int fa[N][22], d[N];
int dfn[N], dfn2[N], tot;
int go[N][22];
int route[N][3];
bool vis[N];
vector<int> rt[N];
vector<ques> q[N];
bool ca[N];
int f[N];
int ans[N];
void ins(int x, int y) {
  bian[++cnt].nxt = hd[x];
  bian[cnt].to = y;
  hd[x] = cnt;
}
void dfs1(int x, int dep) {
  d[x] = dep;
  dfn[x] = ++tot;
  for (int i = hd[x]; i; i = bian[i].nxt) {
    int y = bian[i].to;
    if (y != fa[x][0]) {
      fa[y][0] = x;
      dfs1(y, dep + 1);
    }
  }
  dfn2[x] = tot;
}
void dp(int x) {
  go[x][0] = 0;
  for (int i = 0; i < rt[x].size(); i++) {
    int anc = route[rt[x][i]][2];
    if (d[anc] < d[x]) {
      if ((!go[x][0]) || d[go[x][0]] > d[anc]) go[x][0] = anc;
    }
  }
  for (int i = hd[x]; i; i = bian[i].nxt) {
    int y = bian[i].to;
    if (y != fa[x][0]) {
      dp(y);
      if (go[y][0]) {
        if (d[go[y][0]] < d[x]) {
          if (!go[x][0] || d[go[x][0]] > d[go[y][0]]) go[x][0] = go[y][0];
        }
      }
    }
  }
}
int lca(int x, int y) {
  if (d[x] < d[y]) swap(x, y);
  for (int i = L; i >= 0; i--)
    if (d[fa[x][i]] >= d[y]) x = fa[x][i];
  if (x == y) return x;
  for (int i = L; i >= 0; i--)
    if (fa[x][i] != fa[y][i]) x = fa[x][i], y = fa[y][i];
  return fa[x][0];
}
void add(int x) {
  for (; x <= n; x += x & (-x)) f[x]++;
}
int query(int x) {
  int sum = 0;
  for (; x; x -= x & (-x)) sum += f[x];
  return sum;
}
void dfs2(int x) {
  vis[x] = 1;
  for (int i = 0; i < q[x].size(); i++) {
    int y = q[x][i].to;
    int zong = query(dfn2[y]) - query(dfn[y] - 1);
    q[x][i].fir = zong;
  }
  for (int i = 0; i < rt[x].size(); i++) {
    int y = (route[rt[x][i]][1] == x) ? route[rt[x][i]][0] : route[rt[x][i]][1];
    add(dfn[y]);
  }
  for (int i = hd[x]; i; i = bian[i].nxt) {
    int y = bian[i].to;
    if (y != fa[x][0]) {
      dfs2(y);
    }
  }
  for (int i = 0; i < q[x].size(); i++) {
    int y = q[x][i].to;
    int now = query(dfn2[y]) - query(dfn[y] - 1);
    if (q[x][i].fir < now) {
      ans[q[x][i].id] = q[x][i].has + 1;
    } else {
      if (ca[q[x][i].id])
        ans[q[x][i].id] = q[x][i].has + 2;
      else
        ans[q[x][i].id] = -1;
    }
  }
}
int main() {
  scanf("%d", &n);
  int t;
  for (int i = 2; i <= n; i++) {
    scanf("%d", &t);
    ins(t, i);
    ins(i, t);
  }
  scanf("%d", &m);
  dfs1(1, 1);
  d[0] = -1;
  for (int j = 1; j <= L; j++)
    for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
  for (int i = 1; i <= m; i++) {
    scanf("%d%d", &route[i][0], &route[i][1]);
    rt[route[i][0]].push_back(i);
    rt[route[i][1]].push_back(i);
    route[i][2] = lca(route[i][1], route[i][0]);
  }
  dp(1);
  for (int j = 1; j <= L; j++)
    for (int i = 1; i <= n; i++) go[i][j] = go[go[i][j - 1]][j - 1];
  scanf("%d", &Q);
  int st, ed;
  for (int i = 1; i <= Q; i++) {
    scanf("%d%d", &st, &ed);
    que[i][0] = st, que[i][1] = ed;
    int anc = lca(st, ed);
    if (anc == st || anc == ed) {
      if (d[st] < d[ed]) swap(st, ed);
      int sum = 0;
      bool fl = false;
      for (int j = L; j >= 0; j--) {
        if (d[go[st][j]] > d[ed]) {
          if (st != go[st][j]) st = go[st][j], sum += 1 << j;
        } else if (go[st][j])
          fl = true;
      }
      if (fl)
        ans[i] = sum + 1;
      else
        ans[i] = -1;
    } else {
      int sst = 0, sed = 0;
      bool cst = false, ced = false;
      for (int j = L; j >= 0; j--) {
        if (d[go[st][j]] > d[anc]) {
          if (st != go[st][j]) st = go[st][j], sst += (1 << j);
        } else if (go[st][j])
          cst = true;
      }
      for (int j = L; j >= 0; j--) {
        if (d[go[ed][j]] > d[anc]) {
          if (ed != go[ed][j]) ed = go[ed][j], sed += (1 << j);
        } else if (go[ed][j])
          ced = true;
      }
      ca[i] = (cst && ced);
      ques nn;
      nn.id = i;
      nn.lca = anc, nn.to = ed;
      nn.has = sed + sst;
      q[st].push_back(nn);
      ques mm = nn;
      mm.to = st;
      q[ed].push_back(mm);
    }
  }
  dfs2(1);
  for (int i = 1; i <= Q; i++) {
    printf("%d\n", ans[i]);
  }
  return 0;
}