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;
char buf[1 << 20], pbuf[1 << 20], *p1, *p2, *pf = pbuf;
template <typename T>
void rin(T &t) {
  t = 0;
  char c =
      (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
           ? 0
           : *p1++);
  while (c < 48 || c > 57)
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? 0
             : *p1++);
  while (48 <= c && c <= 57) {
    t = (t << 1) + (t << 3) + c - '0';
    c = (p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 20, stdin), p1 == p2)
             ? 0
             : *p1++);
  }
}
inline void push(const char c) {
  if (pf - pbuf == 1 << 20) fwrite(pbuf, 1, 1 << 20, stdout), pf = pbuf;
  *pf++ = c;
}
template <typename T>
void print(T x) {
  static short sta[35], top = 0;
  if (x < 0) x = -x, push('-');
  do {
    sta[++top] = x % 10;
    x /= 10;
  } while (x);
  while (top) push(sta[top--] + '0');
  push('\n');
}
const int maxn = 200000 + 5;
int fa[maxn][20], Next[maxn], End[maxn], tot, Last[maxn], in[maxn], ou[maxn],
    dfn, dep[maxn], f[maxn][20], n, m, q;
inline void link(int a, int b) {
  Next[++tot] = Last[a];
  Last[a] = tot;
  End[tot] = b;
}
struct Subway {
  int s, t, id, lca;
} subway[maxn];
void dfs(int x) {
  in[x] = ++dfn;
  dep[x] = dep[fa[x][0]] + 1;
  int k = log2(dep[x]);
  for (int i = 1; i <= k; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
  for (int i = Last[x]; i; i = Next[i]) {
    int v = End[i];
    dfs(v);
  }
  ou[x] = dfn;
}
int mark[maxn];
int getlca(int x, int y) {
  int k, s;
  if (dep[x] != dep[y]) {
    if (dep[x] < dep[y]) {
      k = x;
      x = y;
      y = k;
    }
    s = dep[x] - dep[y];
    k = log2(s);
    for (int i = k; i >= 0; i--)
      if (s >> i & 1) x = fa[x][i];
  }
  if (x == y) return x;
  k = log2(dep[x]);
  for (int i = k; i >= 0; i--)
    if (fa[x][i] != fa[y][i] && fa[x][i] && fa[y][i]) {
      x = fa[x][i];
      y = fa[y][i];
    }
  return fa[x][0];
}
void dp(int x) {
  for (int i = Last[x]; i; i = Next[i]) {
    int v = End[i];
    dp(v);
    if (mark[v]) {
      if (!mark[x]) {
        if (dep[x] > dep[mark[v]]) mark[x] = mark[v];
      } else if (dep[mark[x]] > dep[mark[v]])
        mark[x] = mark[v];
    }
  }
  f[x][0] = mark[x];
}
int Ans[maxn];
bool book[maxn];
inline int Min(int a, int b) { return a > b ? b : a; }
struct erweizhaodain {
  pair<int, int> node[maxn << 1];
  struct Solve {
    int id, x, y;
    bool flag;
    Solve(int id, int x, int y, bool flag) {
      this->id = id;
      this->x = x;
      this->y = y;
      this->flag = flag;
    }
    bool operator<(const Solve &a) const { return x < a.x; }
  };
  struct Query {
    bool flag;
    int x1, y1, x2, y2, id, v, ans;
    Query(int sx, int sy, int tx, int ty, int id, bool flag, int ans) {
      this->x1 = sx;
      this->y1 = sy;
      this->x2 = tx;
      this->y2 = ty;
      this->id = id;
      this->flag = flag;
      this->v = 0;
      this->ans = ans;
    }
  };
  int c[maxn];
  void modify(int x, int d) {
    for (x; x <= n; x += (x & -x)) c[x] += d;
  }
  int getsum(int x) {
    int sum = 0;
    for (x; x; x -= (x & -x)) sum += c[x];
    return sum;
  }
  vector<Query> query;
  vector<Solve> solve;
  vector<Query>::iterator it;
  void insert_Query(int sx, int tx, int sy, int ty, int id, bool flag,
                    int ans) {
    query.push_back(Query(sx, sy, tx, ty, id, flag, ans));
  }
  void work() {
    for (it = query.begin(); it != query.end(); it++) {
      if (it->x1 - 1 && it->y1 - 1)
        solve.push_back(
            Solve(it - query.begin(), it->x1 - 1, it->y1 - 1, true));
      if (it->x1 - 1)
        solve.push_back(Solve(it - query.begin(), it->x1 - 1, it->y2, false));
      if (it->y1 - 1)
        solve.push_back(Solve(it - query.begin(), it->x2, it->y1 - 1, false));
      solve.push_back(Solve(it - query.begin(), it->x2, it->y2, true));
    }
    sort(solve.begin(), solve.end());
    vector<Solve>::iterator it1;
    for (int i = 1; i <= m; i++)
      node[i].first = in[subway[i].s], node[i].second = in[subway[i].t];
    for (int i = 1; i <= m; i++)
      node[i + m].first = in[subway[i].t], node[i + m].second = in[subway[i].s];
    sort(node + 1, node + 1 + 2 * m);
    int j = 0;
    for (it1 = solve.begin(); it1 != solve.end(); it1++) {
      while (j + 1 <= 2 * m && node[j + 1].first <= it1->x) {
        modify(node[j + 1].second, 1);
        j++;
      }
      if (it1->flag)
        query[it1->id].v += getsum(it1->y);
      else
        query[it1->id].v -= getsum(it1->y);
    }
    for (it = query.begin(); it != query.end(); it++) {
      if (it->v) {
        if (Ans[it->id] == it->ans || Ans[it->id] > it->ans + 1)
          Ans[it->id] = it->ans + 1;
        book[it->id] = false;
      } else {
        if (it->flag) {
          if (Ans[it->id] == it->ans) book[it->id] = true;
        } else if (Ans[it->id] == it->ans || Ans[it->id] > it->ans + 2)
          Ans[it->id] = it->ans + 2;
      }
    }
  }
} solve1;
inline void solve(int id, int x, int y) {
  if (x == y) Ans[id] = 1;
  int lca = getlca(x, y);
  int k;
  int &ans = Ans[id];
  if (x == lca || y == lca) {
    if (dep[x] < dep[y]) {
      k = x;
      x = y;
      y = k;
    }
    k = log2(dep[x]);
    for (int i = k; i >= 0; i--)
      if (dep[f[x][i]] > dep[y] && f[x][i]) x = f[x][i], ans += 1 << i;
    if (f[x][0] && dep[f[x][0]] <= dep[y])
      ans++;
    else
      book[id] = true;
    return;
  }
  k = log2(dep[x]);
  for (int i = k; i >= 0; i--)
    if (f[x][i] && dep[f[x][i]] > dep[lca]) x = f[x][i], ans += 1 << i;
  k = log2(dep[y]);
  for (int i = k; i >= 0; i--)
    if (f[y][i] && dep[f[y][i]] > dep[lca]) y = f[y][i], ans += 1 << i;
  bool flag = false;
  if ((f[x][0] && dep[f[x][0]] <= dep[lca]) &&
      (f[y][0] && dep[f[y][0]] <= dep[lca]))
    flag = true;
  solve1.insert_Query(in[x], ou[x], in[y], ou[y], id, !flag, ans);
  if (f[y][0] && f[x][0] == lca && dep[f[y][0]] < dep[lca]) {
    ans += 2;
    return;
  }
  if (f[x][0] && f[y][0] == lca && dep[f[x][0]] < dep[lca]) {
    ans += 2;
    return;
  }
}
int main() {
  rin(n);
  int x, y;
  for (int i = 2; i <= n; i++) {
    rin(x);
    fa[i][0] = x;
    link(x, i);
  }
  dfs(1);
  rin(m);
  for (int i = 1; i <= m; i++) {
    rin(subway[i].s);
    rin(subway[i].t);
    subway[i].lca = getlca(subway[i].s, subway[i].t);
    if (dep[mark[subway[i].s]] > dep[subway[i].lca] ||
        !mark[subway[i].s] && subway[i].s != subway[i].lca)
      mark[subway[i].s] = subway[i].lca;
    if (dep[mark[subway[i].t]] > dep[subway[i].lca] ||
        !mark[subway[i].t] && subway[i].t != subway[i].lca)
      mark[subway[i].t] = subway[i].lca;
  }
  dp(1);
  for (int x = 1; x <= n; x++) {
    int k = log2(dep[x]);
    for (int i = 1; i <= k; i++) f[x][i] = f[f[x][i - 1]][i - 1];
  }
  rin(q);
  for (int i = 1; i <= q; i++) {
    rin(x);
    rin(y);
    solve(i, x, y);
  }
  solve1.work();
  for (int i = 1; i <= q; i++) print(book[i] ? -1 : Ans[i]);
  fwrite(pbuf, 1, pf - pbuf, stdout);
}