#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
void solve(int cs) {
int n, q;
cin >> n >> q;
vector<vector<int>> g(n);
for (int i = 0; i < n; i++) {
int u, v;
cin >> u >> v, --u, --v;
g[u].push_back(v);
g[v].push_back(u);
}
vector<int> d(n, 0);
auto dfs = [&](auto &&self, int node, int par) -> void {
for (auto &nodes : g[node]) {
if (nodes != par) {
d[nodes] = d[node] + 1;
self(self, nodes, node);
}
}
};
dfs(dfs, 0, -1);
int lim = 1e5 + 2;
vector <int> ans(lim);
for (int i = 0; i < n; i++) {
ans[d[i] + 1] += 1;
}
for (int i = 1; i < lim; i++) ans[i] += ans[i - 1];
while (q--) {
int v;
cin >> v;
cout << ans[v - 1] << "\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(cs);
}
return 0;
}