Problem: There are n cities in Treeland connected with n - 1 bidirectional roads in such that a way that any city is reachable from any other; in other words, the graph of cities and roads is a tree. Treeland is preparing for a seasonal virus epidemic, and currently, they are trying to evaluate different infection scenarios.

In each scenario, several cities are initially infected with different virus species. Suppose that there are k_i virus species in the i-th scenario. Let us denote v_j the initial city for the virus j, and s_j the propagation speed of the virus j. The spread of the viruses happens in turns: first virus 1 spreads, followed by virus 2, and so on. After virus k_i spreads, the process starts again from virus 1.

A spread turn of virus j proceeds as follows. For each city x not infected with any virus at the start of the turn, at the end of the turn it becomes infected with virus j if and only if there is such a city y that:

  * city y was infected with virus j at the start of the turn;
  * the path between cities x and y contains at most s_j edges;
  * all cities on the path between cities x and y (excluding y) were uninfected with any virus at the start of the turn.



Once a city is infected with a virus, it stays infected indefinitely and can not be infected with any other virus. The spread stops once all cities are infected.

You need to process q independent scenarios. Each scenario is described by k_i virus species and m_i important cities. For each important city determine which the virus it will be infected by in the end.

Input

The first line contains a single integer n (1 ≤ n ≤ 2 ⋅ 10^5) — the number of cities in Treeland.

The following n - 1 lines describe the roads. The i-th of these lines contains two integers x_i and y_i (1 ≤ x_i, y_i ≤ n) — indices of cities connecting by the i-th road. It is guaranteed that the given graph of cities and roads is a tree.

The next line contains a single integer q (1 ≤ q ≤ 2 ⋅ 10^5) — the number of infection scenarios. q scenario descriptions follow.

The description of the i-th scenario starts with a line containing two integers k_i and m_i (1 ≤ k_i, m_i ≤ n) — the number of virus species and the number of important cities in this scenario respectively. It is guaranteed that ∑_{i = 1}^ q k_i and ∑_{i = 1}^ q m_i do not exceed 2 ⋅ 10^5.

The following k_i lines describe the virus species. The j-th of these lines contains two integers v_j and s_j (1 ≤ v_j ≤ n, 1 ≤ s_j ≤ 10^6) – the initial city and the propagation speed of the virus species j. It is guaranteed that the initial cities of all virus species within a scenario are distinct.

The following line contains m_i distinct integers u_1, …, u_{m_i} (1 ≤ u_j ≤ n) — indices of important cities.

Output

Print q lines. The i-th line should contain m_i integers — indices of virus species that cities u_1, …, u_{m_i} are infected with at the end of the i-th scenario.

Example

Input


7
1 2
1 3
2 4
2 5
3 6
3 7
3
2 2
4 1
7 1
1 3
2 2
4 3
7 1
1 3
3 3
1 1
4 100
7 100
1 2 3


Output


1 2
1 1
1 1 1

Solution (in CPP):

Solution:
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 + 50;
const int LGMAX = 20;
const int INF = 1e9;
vector<int> adj[N];
struct LCA {
  int n;
  pair<int, int> node[3 * N], rmq[3 * N][LGMAX];
  int id[3 * N], flog[3 * N];
  void build() {
    n = 0;
    dfs(1);
    buildRmq();
    flog[1] = 0;
    for (int i = int(2); i < int(n + 1); ++i) flog[i] = flog[i / 2] + 1;
  }
  void dfs(int u, int p = -1, int d = 0) {
    id[u] = n;
    node[n++] = {d, u};
    for (int v : adj[u])
      if (v != p) {
        dfs(v, u, d + 1);
        node[n++] = {d, u};
      }
  }
  void buildRmq() {
    for (int i = 0; i < n; ++i) rmq[i][0] = node[i];
    for (int lg = 1, pw = 1; lg < LGMAX; ++lg, pw *= 2) {
      for (int i = 0; i < n; ++i) {
        if (i + pw < n)
          rmq[i][lg] = min(rmq[i][lg - 1], rmq[i + pw][lg - 1]);
        else
          rmq[i][lg] = rmq[i][lg - 1];
      }
    }
  }
  int query(int u, int v) {
    int i = id[u], j = id[v];
    if (i > j) swap(i, j);
    if (i == j) return rmq[i][0].second;
    int lg = flog[j - i];
    int pw = (1 << lg);
    return min(rmq[i][lg], rmq[j - pw + 1][lg]).second;
  }
};
LCA Lca;
int cnt, id[N], esp[N], ans[N], dep[N], tim[N], dist[N];
vector<pair<int, int> > auxt[N];
inline int __lca(int a, int b) { return Lca.query(a, b); }
void dfs(int u, int p = 0, int d = 0) {
  id[u] = cnt++;
  dep[u] = d;
  for (int v : adj[u])
    if (v != p) dfs(v, u, d + 1);
}
void go(vector<pair<int, int> > &virus, vector<int> &nodes) {
  priority_queue<pair<pair<int, int>, int>, vector<pair<pair<int, int>, int> >,
                 greater<pair<pair<int, int>, int> > >
      pq;
  for (int x : nodes) dist[x] = tim[x] = INF;
  for (int i = 0; i < int(virus.size()); ++i) {
    ans[virus[i].first] = i;
    dist[virus[i].first] = tim[virus[i].first] = 0;
    pq.push({{0, i}, virus[i].first});
  }
  while (int(pq.size())) {
    auto tup = pq.top();
    pq.pop();
    int t = tup.first.first, id = tup.first.second, u = tup.second;
    int speed = virus[id].second;
    if (t != tim[u] || id != ans[u]) continue;
    for (pair<int, int> par : auxt[u]) {
      int v = par.first, cost = par.second;
      int tv = (dist[u] + cost + speed - 1) / speed;
      if (tv < tim[v] || (tv == tim[v] && ans[u] < ans[v])) {
        tim[v] = tv;
        dist[v] = dist[u] + cost;
        ans[v] = ans[u];
        pq.push({{tim[v], ans[v]}, v});
      }
    }
  }
}
int main() {
  int n, a, b;
  scanf("%d", &n);
  for (int i = 0; i < n - 1; ++i) {
    scanf("%d %d", &a, &b);
    adj[a].push_back(b);
    adj[b].push_back(a);
  }
  dfs(1);
  Lca.build();
  int q;
  scanf("%d", &q);
  while (q--) {
    int k, m;
    scanf("%d %d", &k, &m);
    vector<int> imp(m);
    vector<pair<int, int> > virus(k);
    for (int i = int(0); i < int(k); ++i)
      scanf("%d %d", &virus[i].first, &virus[i].second);
    for (int i = int(0); i < int(m); ++i) scanf("%d", &imp[i]);
    for (int x : imp) esp[x] = 1;
    vector<int> vec(k + m);
    for (int i = int(0); i < int(k); ++i) vec[i] = virus[i].first;
    for (int i = int(0); i < int(m); ++i) vec[i + k] = imp[i];
    sort(vec.begin(), vec.end(),
         [&](const int a, const int b) { return id[a] < id[b]; });
    for (int i = 1, lim = int(vec.size()); i < lim; ++i) {
      vec.push_back(__lca(vec[i - 1], vec[i]));
    }
    sort(vec.begin(), vec.end(),
         [&](const int a, const int b) { return id[a] < id[b]; });
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    for (int i = 1; i < int(vec.size()); ++i) {
      int u = vec[i - 1], v = vec[i];
      u = __lca(u, v);
      auxt[u].push_back({v, dep[v] - dep[u]});
      auxt[v].push_back({u, dep[v] - dep[u]});
    }
    go(virus, vec);
    for (int i = 0; i < m; ++i) printf("%d ", ans[imp[i]] + 1);
    printf("\n");
    for (int x : vec) auxt[x].clear();
    for (int x : imp) esp[x] = 0;
  }
  return 0;
}