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;
clock_t timeStart, timeFinish;
void timeBegin() { timeStart = clock(); }
void timeEnd() { timeFinish = clock(); }
void timeDuration() {
  timeEnd();
  double time_taken = double(timeFinish - timeStart) / double(CLOCKS_PER_SEC);
  cout << "Time taken by program is : " << fixed << time_taken
       << setprecision(5);
  cout << " sec " << endl;
}
class InputReader {
 public:
  InputReader() {
    input_file = stdin;
    cursor = 0;
    fread(buffer, SIZE, 1, input_file);
  }
  InputReader(const char *file_name) {
    input_file = fopen(file_name, "r");
    cursor = 0;
    fread(buffer, SIZE, 1, input_file);
  }
  inline InputReader &operator>>(int &n) {
    while ((buffer[cursor] < '0' || buffer[cursor] > '9') &&
           buffer[cursor] != '-') {
      advance();
    }
    int sign = 1;
    if (buffer[cursor] == '-') {
      sign = -1;
      advance();
    }
    n = 0;
    while ('0' <= buffer[cursor] && buffer[cursor] <= '9') {
      n = n * 10 + buffer[cursor] - '0';
      advance();
    }
    n *= sign;
    return *this;
  }

 private:
  FILE *input_file;
  static const int SIZE = 1 << 17;
  int cursor;
  char buffer[SIZE];
  inline void advance() {
    ++cursor;
    if (cursor == SIZE) {
      cursor = 0;
      fread(buffer, SIZE, 1, input_file);
    }
  }
};
const int MAXN = 200000;
const int MAXLOG = 18;
const int INF = 1000000000;
vector<int> g[1 + MAXN];
vector<pair<int, int> > t[1 + MAXN];
int dad[1 + MAXLOG][1 + MAXN], answer[1 + MAXN], virusId[1 + MAXN];
int counter = 0, start[1 + MAXN], finish[1 + MAXN], depth[1 + MAXN];
int speed[1 + MAXN], id[1 + MAXN], virus[1 + MAXN], city[1 + MAXN],
    st[1 + MAXN];
void DFS(int node, int father) {
  dad[0][node] = father;
  depth[node] = depth[father] + 1;
  for (int i = 1; (1 << i) < depth[node]; i++) {
    dad[i][node] = dad[i - 1][dad[i - 1][node]];
  }
  start[node] = ++counter;
  for (auto son : g[node]) {
    if (son != father) {
      DFS(son, node);
    }
  }
  finish[node] = counter;
}
int raise(int node, int delta) {
  for (int i = 0; i < MAXLOG; i++) {
    if ((delta >> i) & 1) {
      node = dad[i][node];
    }
  }
  return node;
}
bool isParent(int a, int b) {
  return start[a] <= start[b] && finish[b] <= finish[a];
}
int lca(int a, int b) {
  if (depth[a] < depth[b]) {
    swap(a, b);
  }
  a = raise(a, depth[a] - depth[b]);
  for (int i = MAXLOG - 1; i >= 0; i--) {
    if (dad[i][a] != dad[i][b]) {
      a = dad[i][a];
      b = dad[i][b];
    }
  }
  if (a != b) {
    a = dad[0][a];
    b = dad[0][b];
  }
  return a;
}
inline bool compareStart(const int &a, const int &b) {
  return start[a] < start[b];
}
void sortUnique(vector<int> &v) {
  sort(v.begin(), v.end(), compareStart);
  v.resize(unique(v.begin(), v.end()) - v.begin());
}
pair<int, int> d[1 + MAXN];
bool isSmaller(int c1, int s1, int c2, int s2) {
  int t1 = (c1 == 0 ? 0 : (c1 - 1) / speed[s1] + 1);
  int t2 = (c2 == 0 ? 0 : (c2 - 1) / speed[s2] + 1);
  return make_pair(t1, virusId[s1]) < make_pair(t2, virusId[s2]);
}
bool seen[1 + MAXN];
void dijkstra(vector<int> &v) {
  priority_queue<pair<pair<int, int>, pair<int, int> >,
                 vector<pair<pair<int, int>, pair<int, int> > >,
                 greater<pair<pair<int, int>, pair<int, int> > > >
      h;
  for (auto node : v) {
    if (virusId[node] != 0) {
      d[node] = {0, virusId[node]};
      h.push({{0, virusId[node]}, {node, 0}});
    } else {
      d[node] = {INF, 0};
    }
  }
  while (!h.empty()) {
    int r = h.top().first.first, s = h.top().first.second,
        node = h.top().second.first, c = h.top().second.second;
    h.pop();
    if (seen[node]) {
      continue;
    }
    seen[node] = true;
    for (auto it : t[node]) {
      int other = it.first, l = it.second;
      int r0 = (c + l - 1) / speed[s] + 1, s0 = s;
      if (make_pair(r0, s0) < d[other]) {
        d[other] = {r0, s0};
        h.push({{r0, s0}, {other, c + l}});
      }
    }
  }
}
void solve(int k, int m) {
  vector<int> v;
  for (int i = 1; i <= k; i++) {
    v.push_back(virus[i]);
  }
  for (int i = 1; i <= m; i++) {
    v.push_back(city[i]);
  }
  sortUnique(v);
  int x = v.size();
  for (int i = 0; i + 1 < x; i++) {
    v.push_back(lca(v[i], v[i + 1]));
  }
  sortUnique(v);
  int top = 1;
  st[top] = v[0];
  for (int i = 1; i < v.size(); i++) {
    int node = v[i];
    while (!isParent(st[top], node)) {
      top--;
    }
    int l = depth[node] - depth[st[top]];
    t[st[top]].push_back({node, l});
    t[node].push_back({st[top], l});
    top++;
    st[top] = node;
  }
  dijkstra(v);
  for (auto node : v) {
    seen[node] = false;
    t[node].clear();
    if (id[node] != 0) {
      answer[id[node]] = d[node].second;
    }
  }
}
int main() {
  timeBegin();
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  speed[0] = 1;
  int n;
  cin >> n;
  for (int i = 1; i < n; i++) {
    int a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  DFS(1, 0);
  int q;
  cin >> q;
  for (int i = 1; i <= q; i++) {
    int k, m;
    cin >> k >> m;
    for (int i = 1; i <= k; i++) {
      cin >> virus[i] >> speed[i];
      virusId[virus[i]] = i;
    }
    for (int i = 1; i <= m; i++) {
      cin >> city[i];
      id[city[i]] = i;
    }
    solve(k, m);
    for (int i = 1; i <= m; i++) {
      cout << answer[i] << " ";
    }
    cout << "\n";
    for (int i = 1; i <= k; i++) {
      virusId[virus[i]] = 0;
    }
    for (int i = 1; i <= m; i++) {
      id[city[i]] = 0;
    }
  }
  return 0;
}