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 INF = 0x3f3f3f3f;
const int MAXN = 2e5 + 10;
const int MAXM = 4e5 + 10;
const int MAX_LOG = 18;
int m;
int p[19][MAXN], n, depth[MAXN];
pair<int, int> sq[MAXN];
int dp[MAX_LOG + 1][MAXN];
vector<int> each[MAXN];
void init() {
  for (int i = 1; i <= MAX_LOG; ++i) {
    for (int j = 1; j <= n; ++j) {
      p[i][j] = p[i - 1][p[i - 1][j]];
    }
  }
}
int lca(int u, int v) {
  if (depth[u] > depth[v]) swap(u, v);
  for (int i = 0; i <= MAX_LOG; ++i) {
    if (((depth[v] - depth[u]) >> i) & 1) {
      v = p[i][v];
    }
  }
  if (u == v) return u;
  for (int i = MAX_LOG; i >= 0; --i) {
    if (p[i][u] != p[i][v]) {
      u = p[i][u];
      v = p[i][v];
    }
  }
  return p[0][u];
}
void dfs(int now, int dpp) {
  depth[now] = dpp;
  for (int it : each[now]) {
    dfs(it, dpp + 1);
  }
}
int Cnt = 0;
void dfs2(int now) {
  sq[now].first = ++Cnt;
  for (int it : each[now]) {
    dfs2(it);
  }
  sq[now].second = ++Cnt;
}
int hest[MAXN];
int dfs3(int now) {
  for (int it : each[now]) {
    hest[now] = min(hest[now], dfs3(it));
  }
  return dp[0][now] = hest[now];
}
bool cmp(int A, int B) { return A < B; }
int U, V;
int query(int u, int v, int col = 0) {
  int tmp = 0;
  if (u == v) {
    return 0;
  }
  for (int i = MAX_LOG; i >= 0; --i) {
    if (dp[i][u] != INF)
      if (dp[i][u] > v) {
        u = dp[i][u];
        tmp += (1 << i);
      }
  }
  if (dp[0][u] > v) {
    return -1;
  }
  if (col == 1) {
    U = u;
  }
  if (col == 2) {
    V = u;
  }
  return tmp + 1;
}
vector<pair<int, int> > better[MAXN];
vector<int> sup[MAXN];
struct BIT {
  int bit[MAXN + MAXN + 10] = {0}, n;
  int sum(int i) {
    int s = 0;
    while (i > 0) {
      s += bit[i];
      i -= i & (-i);
    }
    return s;
  }
  int query(int l, int r) { return sum(r) - sum(l - 1); }
  void add(int i, int x = 1) {
    while (i <= n) {
      bit[i] += x;
      i += i & (-i);
    }
  }
} rmq;
int res[MAXN];
void update(int now) {
  vector<int> shuzu;
  for (int i = 0; i < better[now].size(); ++i) {
    shuzu.push_back(rmq.query(sq[better[now][i].first].first,
                              sq[better[now][i].first].second));
  }
  for (auto it : each[now]) {
    update(it);
  }
  for (auto it : sup[now]) {
    rmq.add(sq[it].first);
  }
  for (int i = 0; i < better[now].size(); ++i) {
    if (rmq.query(sq[better[now][i].first].first,
                  sq[better[now][i].first].second) > shuzu[i]) {
      res[better[now][i].second]--;
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  cin >> n;
  rmq.n = n << 1;
  for (int i = 2; i <= n; ++i) cin >> p[0][i], each[p[0][i]].push_back(i);
  for (int i = 1; i <= n; ++i) {
    sort(each[i].begin(), each[i].end());
  }
  dfs(1, 1);
  init();
  dfs2(1);
  cin >> m;
  memset(hest, 0x3f, sizeof(hest));
  for (int i = 1; i <= m; ++i) {
    int u, v;
    cin >> u >> v;
    if (depth[u] > depth[v]) swap(u, v);
    int l = lca(u, v);
    if (l != v) {
      hest[u] = min(hest[u], l);
      hest[v] = min(hest[v], l);
      if (sq[u].first > sq[v].first) {
        swap(u, v);
      }
      sup[u].push_back(v);
    } else {
      hest[u] = min(hest[u], v);
    }
  }
  dfs3(1);
  for (int i = 1; i <= MAX_LOG; ++i) {
    for (int j = 1; j <= n; ++j) {
      if (dp[i - 1][j] != INF && dp[i - 1][dp[i - 1][j]] != INF) {
        dp[i][j] = dp[i - 1][dp[i - 1][j]];
      }
    }
  }
  int q;
  cin >> q;
  int i = 1;
  memset(res, 63, sizeof(res));
  while (i <= q) {
    int u, v;
    cin >> u >> v;
    if (depth[u] < depth[v]) {
      swap(u, v);
    }
    int l = lca(u, v);
    if (l == v) {
      res[i] = query(u, v);
    } else {
      if (query(u, l) < 0 || query(v, l) < 0) {
        res[i] = -1;
      } else {
        res[i] = query(u, l, 1) + query(v, l, 2);
        if (sq[U].first > sq[V].first) {
          swap(U, V);
        }
        better[U].push_back(make_pair(V, i));
      }
    }
    i++;
  }
  update(1);
  for (int i = 1; i <= q; ++i) {
    cout << res[i] << endl;
  }
  return 0;
}