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>
#pragma GCC optimize(3)
using namespace std;
bool Finish_read;
template <class T>
inline void read(T &x) {
  Finish_read = 0;
  x = 0;
  int f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    if (ch == EOF) return;
    ch = getchar();
  }
  while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
  x *= f;
  Finish_read = 1;
}
template <class T>
inline void print(T x) {
  if (x / 10 != 0) print(x / 10);
  putchar(x % 10 + '0');
}
template <class T>
inline void writeln(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
  putchar('\n');
}
template <class T>
inline void write(T x) {
  if (x < 0) putchar('-');
  x = abs(x);
  print(x);
}
int pre[400550][22], C[400550], dfn[400550], vend[400550], fa[400550][22],
    dep[400550], cnt[400550], vis[400550];
int S[400550], T[400550], cur, answer[400550], num[400550];
int n, t, m, _dfn;
vector<int> G[400550];
vector<int> p[400550];
vector<int> quest[400550 * 2];
inline int lowbit(int x) { return x & (-x); }
inline int sum(int x) {
  int ret = 0;
  while (x > 0) {
    ret += C[x];
    x -= lowbit(x);
  }
  return ret;
}
inline void add(int x) {
  while (x <= vend[1]) {
    C[x]++;
    x += lowbit(x);
  }
}
void DFS(int x, int depth) {
  if (vis[x]) return;
  vis[x] = 1;
  int siz = G[x].size();
  dfn[x] = ++_dfn;
  dep[x] = depth;
  if (!siz) {
    vend[x] = dfn[x];
    return;
  }
  for (int i = 0, v; i < siz; i++) {
    v = G[x][i];
    if (!vis[v]) fa[v][0] = x;
    DFS(v, depth + 1);
  }
  vend[x] = ++_dfn;
}
void get_pre(int x) {
  if (!vis[x]) return;
  vis[x] = 0;
  int siz = G[x].size();
  for (int i = 0; i < siz; i++) get_pre(G[x][i]);
  if (dfn[pre[x][0]] < dfn[pre[fa[x][0]][0]]) pre[fa[x][0]][0] = pre[x][0];
}
inline void find_fa(void) {
  for (int j = 1; j <= 17; j++)
    for (int i = 1; i <= n; i++) fa[i][j] = fa[fa[i][j - 1]][j - 1];
}
inline void move_up(void) {
  get_pre(1);
  for (int i = 1; i <= n; i++)
    if (!pre[i][0]) pre[i][0] = i;
  for (int j = 1; j <= 17; j++) {
    for (int i = 1; i <= n; i++) {
      pre[i][j] = pre[pre[i][j - 1]][j - 1];
    }
  }
}
inline int LCA(int x, int y) {
  if (dep[x] < dep[y]) swap(x, y);
  int i;
  for (i = 0; dep[x] - (1 << i) >= dep[y]; i++) x = fa[x][i];
  if (dep[x] >= dep[y]) {
    for (int j = i - 1; j >= 0; j--)
      if (dep[fa[x][j]] >= dep[y]) x = fa[x][j];
  }
  for (i = 0; fa[x][i] != fa[y][i]; i++) {
    x = fa[x][i];
    y = fa[y][i];
  }
  for (int j = i - 1; j >= 0; j--) {
    if (fa[x][j] != fa[y][j]) {
      x = fa[x][j];
      y = fa[y][j];
    }
  }
  return fa[x][0];
}
inline void Add_Point(int x, int y) {
  p[dfn[x]].push_back(dfn[y]);
  p[dfn[y]].push_back(dfn[x]);
}
inline void Deal_Point(void) {
  for (int i = 1; i <= cur; i++) {
    quest[dfn[S[i]] - 1].push_back(-i);
    quest[vend[S[i]]].push_back(i);
  }
  for (int i = 0; i <= _dfn; i++) {
    int siz = p[i].size();
    for (int j = 0; j < siz; j++) add(p[i][j]);
    siz = quest[i].size();
    for (int j = 0; j < siz; j++) {
      int k = abs(quest[i][j]);
      int now = sum(vend[T[k]]) - sum(dfn[T[k]] - 1);
      if (quest[i][j] < 0)
        cnt[k] -= now;
      else
        cnt[k] += now;
    }
  }
  for (int i = 1; i <= cur; i++)
    if (cnt[i] <= 0) answer[num[i]]++;
}
inline int Ask(int x, int y, int k) {
  int ans = 0;
  if (dfn[x] < dfn[y]) swap(x, y);
  if (dfn[x] <= vend[y]) {
    int i;
    for (i = 0; dfn[pre[x][i]] > dfn[y]; i++) {
      if (x == pre[x][i]) return -1;
      x = pre[x][i];
      ans += (1 << i);
    }
    for (int j = i - 1; j >= 0; j--) {
      if (x == pre[x][i]) return -1;
      if (dfn[pre[x][j]] > dfn[y]) {
        x = pre[x][j];
        ans += (1 << j);
      }
    }
  } else {
    int i;
    int lca = LCA(x, y);
    for (i = 0; dfn[pre[x][i]] > dfn[lca]; i++) {
      if (x == pre[x][i]) return -1;
      x = pre[x][i];
      ans += (1 << i);
    }
    for (int j = i - 1; j >= 0; j--) {
      if (x == pre[x][0]) return -1;
      if (dfn[pre[x][j]] > dfn[lca]) {
        x = pre[x][j];
        ans += (1 << j);
      }
    }
    for (i = 0; dfn[pre[y][i]] > dfn[lca]; i++) {
      if (y == pre[y][i]) return -1;
      y = pre[y][i];
      ans += (1 << i);
    }
    for (int j = i - 1; j >= 0; j--) {
      if (y == pre[y][i]) return -1;
      if (dfn[pre[y][j]] > dfn[lca]) {
        y = pre[y][j];
        ans += (1 << j);
      }
    }
    S[++cur] = x;
    T[cur] = y;
    num[cur] = k;
  }
  return ans;
}
int main() {
  read(n);
  int x, y;
  for (int i = 2; i <= n; i++) {
    read(x);
    G[x].push_back(i);
    G[i].push_back(x);
  }
  dfn[0] = 0x3f3f3f3f;
  vend[0] = -0x3f3f3f3f;
  fa[1][0] = 1;
  DFS(1, 1);
  find_fa();
  read(t);
  for (int i = 1; i <= t; i++) {
    read(x);
    read(y);
    if (dfn[x] < dfn[y]) swap(x, y);
    if (vend[x] < vend[y]) {
      if (dfn[pre[x][0]] > dfn[y]) pre[x][0] = y;
    } else {
      int lca = LCA(x, y);
      if (dfn[pre[x][0]] > dfn[lca]) pre[x][0] = lca;
      if (dfn[pre[y][0]] > dfn[lca]) pre[y][0] = lca;
      Add_Point(x, y);
    }
  }
  move_up();
  read(m);
  for (int i = 1, x, y; i <= m; i++) {
    read(x);
    read(y);
    answer[i] = Ask(x, y, i);
  }
  Deal_Point();
  for (int i = 1; i <= m; i++) printf("%d\n", answer[i] + (answer[i] != -1));
}