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 = 400005;
int n, q, K, m, i, j, k, h[N], t[N], num, fa[N], s[N], id[N], size[N], son[N],
    tp[N], dep[N], head[N], adj[N * 2], nxt[N * 2], p[N], cnt, stk[N], top,
    g[N], Head[N], Adj[N * 2], Nxt[N * 2], l, f[N];
void dfs(int x, int dad) {
  size[x] = 1;
  for (int y = head[x]; y; y = nxt[y])
    if (adj[y] != dad) {
      dep[adj[y]] = dep[x] + 1;
      fa[adj[y]] = x;
      dfs(adj[y], x);
      size[x] += size[adj[y]];
      if (!son[x] || size[adj[y]] > size[son[x]]) son[x] = adj[y];
    }
}
void Dfs(int x, int dad) {
  id[x] = ++i;
  if (son[x]) {
    tp[son[x]] = tp[x];
    Dfs(son[x], x);
  }
  for (int y = head[x]; y; y = nxt[y])
    if (adj[y] != dad && adj[y] != son[x]) {
      tp[adj[y]] = adj[y];
      Dfs(adj[y], x);
    }
}
int lca(int a, int b) {
  while (tp[a] != tp[b]) {
    if (dep[tp[a]] < dep[tp[b]]) swap(a, b);
    a = fa[tp[a]];
  }
  return dep[a] < dep[b] ? a : b;
}
int dis(int a, int b) { return dep[a] + dep[b] - 2 * dep[lca(a, b)]; }
bool cmp(int a, int b) { return id[a] < id[b]; }
void addedge(int u, int v) {
  Adj[++l] = v;
  Nxt[l] = Head[u];
  Head[u] = l;
  Adj[++l] = u;
  Nxt[l] = Head[v];
  Head[v] = l;
}
void dzx(int x, int dad) {
  if (s[x])
    f[x] = x;
  else
    f[x] = 0;
  for (int y = Head[x], a, b; y; y = Nxt[y])
    if (Adj[y] != dad) {
      dzx(Adj[y], x);
      if (f[Adj[y]] && (!f[x] ||
                        1ll * (a = dis(f[Adj[y]], x) - 1) / s[f[Adj[y]]] <
                            1ll * (b = dis(f[x], x) - 1) / s[f[x]] ||
                        1ll * (a = dis(f[Adj[y]], x) - 1) / s[f[Adj[y]]] ==
                                1ll * (b = dis(f[x], x) - 1) / s[f[x]] &&
                            h[f[Adj[y]]] < h[f[x]]))
        f[x] = f[Adj[y]];
    }
  if (s[x]) f[x] = x;
}
void phh(int x, int dad, int u) {
  int a, b;
  if (u) {
    if (u && (!f[x] ||
              1ll * (a = dis(u, x) - 1) / s[u] <
                  1ll * (b = dis(f[x], x) - 1) / s[f[x]] ||
              1ll * (a = dis(u, x) - 1) / s[u] ==
                      1ll * (b = dis(f[x], x) - 1) / s[f[x]] &&
                  h[u] < h[f[x]]))
      f[x] = u;
  }
  if (s[x]) f[x] = x;
  for (int y = Head[x]; y; y = Nxt[y])
    if (Adj[y] != dad) phh(Adj[y], x, f[x]);
  Head[x] = 0;
}
int main() {
  scanf("%d", &n);
  for (i = 1; i < n; ++i) {
    scanf("%d%d", &j, &k);
    adj[i * 2 - 1] = k;
    nxt[i * 2 - 1] = head[j];
    head[j] = i * 2 - 1;
    adj[i * 2] = j;
    nxt[i * 2] = head[k];
    head[k] = i * 2;
  }
  dfs(1, -1);
  tp[1] = 1;
  i = 0;
  Dfs(1, -1);
  scanf("%d", &q);
  while (q--) {
    if (n == 10) {
      for (i = 1; i <= n; ++i) s[i] = 0;
    }
    scanf("%d%d", &K, &m);
    num = 0;
    for (i = 1; i <= K; ++i) {
      scanf("%d%d", &j, &k);
      s[j] = k;
      h[j] = i;
      t[++num] = j;
    }
    for (i = 1; i <= m; ++i) {
      scanf("%d", &j);
      g[i] = t[++num] = j;
    }
    t[++num] = 1;
    sort(t + 1, t + 1 + num, cmp);
    cnt = 0;
    for (i = 1; i <= num; i = j) {
      for (j = i; j <= num && t[i] == t[j]; ++j)
        ;
      p[++cnt] = t[i];
    }
    if (cnt == 1) {
      puts("1");
      continue;
    }
    l = 0;
    stk[1] = p[1], stk[2] = p[2];
    top = 2;
    for (i = 3; i <= cnt; ++i) {
      while (top > 1 && dep[lca(stk[top], p[i])] <= dep[stk[top - 1]]) {
        addedge(stk[top - 1], stk[top]);
        --top;
      }
      if ((j = lca(p[i], stk[top])) == stk[top])
        stk[++top] = p[i];
      else {
        addedge(j, stk[top]);
        stk[top] = j;
        stk[++top] = p[i];
      }
    }
    while (top > 1) {
      addedge(stk[top - 1], stk[top]);
      --top;
    }
    dzx(1, -1);
    phh(1, -1, 0);
    for (i = 1; i <= m; ++i) printf("%d ", h[f[g[i]]]);
    puts("");
    for (i = 1; i <= cnt; ++i) s[p[i]] = 0;
  }
  return 0;
}