#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve() {
int n, q;
cin >> n >> q;
vector<vector<int>> g(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
--u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> dist(n, -1);
queue<int> Q;
dist[0] = 0;
Q.push(0);
while (!Q.empty()) {
int node = Q.front();
Q.pop();
for (int neighbor : g[node]) {
if (dist[neighbor] == -1) {
dist[neighbor] = dist[node] + 1;
Q.push(neighbor);
}
}
}
int lim = 1e5 + 2;
vector<int> ans(lim, 0);
for (int i = 0; i < n; i++) {
if (dist[i] < lim) {
ans[dist[i]]++;
}
}
for (int i = 1; i < lim; i++) {
ans[i] += ans[i - 1];
}
while (q--) {
int x;
cin >> x;
if (x < lim) {
cout << ans[x] << "\n";
} else {
cout << n << "\n";
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int tc = 1;
cin >> tc;
for (int cs = 1; cs <= tc; cs++) {
solve();
}
return 0;
}