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 inf = 1e9;
const long long INF = 1e18;
const long double PI = acos(-1);
const long double EPS = 1e-18;
int mod = 998244353;
const int MOD7 = 1000000007;
mt19937 rnd(time(0));
const int MOD9 = 1000000009;
const long long MAXN = 4e5 + 1;
vector<long long> g[MAXN];
long long d[MAXN];
const long long lgg = 19;
long long up[MAXN][lgg];
long long tin[MAXN];
long long tout[MAXN];
long long tl = 0;
void dfs(long long v, long long p) {
  up[v][0] = p;
  d[v] = d[p] + 1;
  for (long long i = 1; i < lgg; ++i) {
    up[v][i] = up[up[v][i - 1]][i - 1];
  }
  tin[v] = tl++;
  for (long long i : g[v]) {
    if (i != p) dfs(i, v);
  }
  tout[v] = tl++;
}
bool pp(long long a, long long b) {
  return tin[a] <= tin[b] && tout[a] >= tout[b];
}
long long lca(long long a, long long b) {
  if (pp(a, b)) return a;
  if (pp(b, a)) return b;
  for (long long i = lgg - 1; i >= 0; --i) {
    if (!pp(up[a][i], b)) a = up[a][i];
  }
  return up[a][0];
}
vector<pair<long long, long long>> compressed[MAXN];
long long dist(long long a, long long b) {
  return d[a] + d[b] - 2 * d[lca(a, b)];
}
vector<pair<long long, long long>> virus;
struct pth {
  long long len, lft, id;
};
bool operator<(pth a, pth b) {
  if (a.len == b.len) {
    if (a.id == b.id) return a.lft > b.lft;
    return a.id < b.id;
  }
  return a.len < b.len;
}
bool operator==(pth a, pth b) {
  return vector<long long>{a.len, a.lft, a.id} ==
         vector<long long>{b.len, b.lft, b.id};
}
bool operator>(pth a, pth b) { return !(a < b || a == b); }
pth recalc(pth a, long long len) {
  if (a.lft < len) {
    long long tlen = len - a.lft;
    long long add = 1 + (tlen - 1) / virus[a.id].second;
    long long xx = (virus[a.id].second - tlen % virus[a.id].second);
    if (xx == virus[a.id].second) xx = 0;
    return {a.len + add, xx, a.id};
  }
  return {a.len, a.lft - len, a.id};
}
long long n, q;
signed main() {
  ios_base::sync_with_stdio(0);
  cout.tie(0);
  cin.tie(0);
  srand(time(NULL));
  cin >> n;
  for (long long i = 0; i < n - 1; ++i) {
    long long a, b;
    cin >> a >> b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  dfs(1, 1);
  cin >> q;
  while (q--) {
    long long k, m;
    cin >> k >> m;
    virus.assign(k, make_pair(0, 0));
    vector<long long> cities;
    vector<long long> imp;
    for (long long i = 0; i < k; ++i) {
      cin >> virus[i].first >> virus[i].second;
    }
    for (long long i = 0; i < m; ++i) {
      long long x;
      cin >> x;
      cities.push_back(x);
    }
    for (long long i : cities) imp.push_back(i);
    for (auto i : virus) {
      imp.push_back(i.first);
    }
    sort((imp).begin(), (imp).end());
    (imp).resize(unique((imp).begin(), (imp).end()) - imp.begin());
    ;
    sort((imp).begin(), (imp).end(),
         [&](long long a, long long b) { return tin[a] < tin[b]; });
    vector<long long> st;
    vector<long long> tlist;
    for (long long i : imp) tlist.push_back(i);
    for (long long i = 0; i + 1 < imp.size(); ++i) {
      tlist.push_back(lca(imp[i], imp[i + 1]));
    }
    sort((tlist).begin(), (tlist).end());
    (tlist).resize(unique((tlist).begin(), (tlist).end()) - tlist.begin());
    ;
    sort((tlist).begin(), (tlist).end(),
         [&](long long a, long long b) { return tin[a] < tin[b]; });
    auto ti = tlist;
    sort((ti).begin(), (ti).end());
    for (long long i = 0; i < ti.size(); ++i) compressed[i].clear();
    for (long long i : tlist) {
      while (st.size() && !pp(st.back(), i)) st.pop_back();
      if (st.size()) {
        long long w = dist(st.back(), i);
        long long kekw =
            lower_bound((ti).begin(), (ti).end(), st.back()) - ti.begin();
        long long lolw = lower_bound((ti).begin(), (ti).end(), i) - ti.begin();
        compressed[kekw].push_back({lolw, w});
        compressed[lolw].push_back({kekw, w});
      }
      st.push_back(i);
    }
    vector<pth> dist(tlist.size(), {inf, inf, inf});
    vector<bool> taken(tlist.size());
    for (long long i = 0; i < virus.size(); ++i) {
      taken[lower_bound((ti).begin(), (ti).end(), virus[i].first) -
            ti.begin()] = 1;
      dist[lower_bound((ti).begin(), (ti).end(), virus[i].first) - ti.begin()] =
          {0, virus[i].second, i};
    }
    set<pair<pth, long long>> q;
    for (long long i = 0; i < tlist.size(); ++i) {
      if (dist[i].len == 0) q.insert({dist[i], i});
    }
    while (q.size()) {
      long long v = q.begin()->second;
      q.erase(q.begin());
      for (auto i : compressed[v]) {
        if (taken[i.first]) continue;
        auto td = recalc(dist[v], i.second);
        if (dist[i.first] > td) {
          q.erase({dist[i.first], i.first});
          dist[i.first] = td;
          q.insert({dist[i.first], i.first});
        }
      }
    }
    for (long long i : cities) {
      long long tv = lower_bound((ti).begin(), (ti).end(), i) - ti.begin();
      cout << dist[tv].id + 1 << ' ';
    }
    cout << '\n';
  }
}