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 = 100000000;
vector<vector<int> > adj(200001), v(200001);
int timer, a[200001], d[200001], start[200001], finish[200001],
    invStart[200001], L[18][200001], T[18][200001];
typedef struct node {
  int leftEnd;
  int rightEnd;
  int ans;
  node *leftChild;
  node *rightChild;
} node;
node *root[200001];
node *CreateNode(int leftEnd, int rightEnd, int count) {
  node *temp = new node;
  temp->leftEnd = leftEnd;
  temp->rightEnd = rightEnd;
  temp->ans = count;
  return temp;
}
node *BuildSkeletonSegmentTree(int leftEnd, int rightEnd) {
  node *temp = CreateNode(leftEnd, rightEnd, 0);
  if (leftEnd != rightEnd) {
    int mid = (leftEnd + rightEnd) / 2;
    temp->leftChild = BuildSkeletonSegmentTree(leftEnd, mid);
    temp->rightChild = BuildSkeletonSegmentTree(mid + 1, rightEnd);
  } else
    temp->leftChild = temp->rightChild = NULL;
  return temp;
}
node *Insert(int i, node *parentNode) {
  node *newNode;
  if (parentNode->leftEnd <= i && i <= parentNode->rightEnd) {
    newNode =
        CreateNode(parentNode->leftEnd, parentNode->rightEnd, parentNode->ans);
    if (parentNode->leftEnd != parentNode->rightEnd) {
      newNode->leftChild = Insert(i, parentNode->leftChild);
      newNode->rightChild = Insert(i, parentNode->rightChild);
    } else
      newNode->leftChild = newNode->rightChild = NULL;
  } else
    newNode = parentNode;
  return newNode;
}
void UpdateNode(node *currentNode, int i, int x) {
  if (i < currentNode->leftEnd || currentNode->rightEnd < i) {
    return;
  } else {
    if (i == currentNode->leftEnd && i == currentNode->rightEnd)
      currentNode->ans += x;
    else {
      UpdateNode(currentNode->leftChild, i, x);
      UpdateNode(currentNode->rightChild, i, x);
      currentNode->ans =
          (currentNode->leftChild)->ans + (currentNode->rightChild)->ans;
    }
  }
}
int Query(node *u, node *v, int l, int r) {
  if (r < l || r < u->leftEnd || u->rightEnd < l)
    return 0;
  else {
    if (l <= u->leftEnd && u->rightEnd <= r) {
      return v->ans - u->ans;
    } else {
      return Query(u->leftChild, v->leftChild, l, r) +
             Query(u->rightChild, v->rightChild, l, r);
    }
  }
}
void BuildLCASparseTable(int n) {
  for (int k = 1; k < 18; ++k)
    for (int i = 1; i <= n; ++i) L[k][i] = L[k - 1][L[k - 1][i]];
}
bool IsAncestor(int u, int v) {
  return (start[u] <= start[v] && finish[v] <= finish[u]);
}
int KthAncestor(int i, int k) {
  for (int j = 18 - 1; k > 0 && j > -1; --j) {
    if ((1 << j) <= k) {
      i = L[j][i];
      k -= (1 << j);
    }
  }
  return i;
}
int ChildWithNode(int i, int j) { return KthAncestor(j, d[j] - d[i] - 1); }
int LCA(int i, int j) {
  if (d[i] > d[j]) {
    swap(i, j);
  }
  j = KthAncestor(j, d[j] - d[i]);
  if (i == j)
    return i;
  else {
    for (int k = 18 - 1; L[0][i] != L[0][j] && k > -1; k--) {
      if (L[k][i] != L[k][j]) i = L[k][i], j = L[k][j];
    }
    return L[0][i];
  }
}
void DFS(int i, int p = 0) {
  d[i] = 1 + d[p];
  L[0][i] = p;
  start[i] = ++timer;
  invStart[start[i]] = i;
  for (auto k : adj[i]) DFS(k, i);
  finish[i] = timer;
}
void OneBusDFS(int i, int p = 0) {
  for (auto k : adj[i]) {
    OneBusDFS(k, i);
    a[start[i]] = min(a[start[i]], a[start[k]]);
  }
  T[0][i] = invStart[a[start[i]]];
}
void PreProcess(int n) {
  OneBusDFS(1);
  for (int k = 1; k < 18; ++k)
    for (int i = 1; i <= n; ++i) T[k][i] = T[k - 1][T[k - 1][i]];
  root[0] = BuildSkeletonSegmentTree(1, n);
  for (int i = 1; i <= n; ++i) {
    root[i] = root[i - 1];
    for (auto x : v[i]) {
      root[i] = Insert(x, root[i]);
      UpdateNode(root[i], x, 1);
    }
  }
}
void AddBus(int i, int j) {
  if (start[i] > start[j]) {
    swap(i, j);
  }
  int k = LCA(i, j);
  a[start[i]] = min(start[k], a[start[i]]);
  a[start[j]] = min(start[k], a[start[j]]);
  if (k != i) {
    v[start[i]].push_back(start[j]);
  }
}
int NumberOfBuses(int &i, int k) {
  int ans = 0;
  for (int j = 18 - 1; j > -1; --j) {
    if (d[T[j][i]] > d[k]) {
      i = T[j][i];
      ans += (1 << j);
    }
  }
  if (d[T[0][i]] <= d[k]) {
    ++ans;
  } else
    ans = inf;
  return ans;
}
int Query(int i, int j) {
  if (start[i] > start[j]) {
    swap(i, j);
  }
  int ans = 0;
  if (IsAncestor(i, j)) {
    ans = NumberOfBuses(j, i);
  } else {
    int k = LCA(i, j);
    ans = NumberOfBuses(i, k) + NumberOfBuses(j, k);
    ans -=
        (Query(root[start[i] - 1], root[finish[i]], start[j], finish[j]) > 0);
  }
  if (ans >= inf) ans = -1;
  return ans;
}
int main() {
  int n, m, q;
  scanf("%d", &n);
  for (int i = 2; i <= n; ++i) {
    int p;
    scanf("%d", &p);
    adj[p].push_back(i);
  }
  DFS(1);
  BuildLCASparseTable(n);
  for (int i = 1; i <= n; ++i) a[i] = i;
  scanf("%d", &m);
  while (m--) {
    int i, j;
    scanf("%d%d", &i, &j);
    AddBus(i, j);
  }
  PreProcess(n);
  scanf("%d", &q);
  while (q--) {
    int i, j;
    scanf("%d%d", &i, &j);
    printf("%d\n", Query(i, j));
  }
  return 0;
}