#include <bits/stdc++.h>
#ifdef LOCAL
#include "../algo/debug.h"
#else
#define debug(...) 0
#endif
using namespace std;
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
int tt;
cin >> tt;
while (tt--) {
int n, q;
cin >> n >> q;
vector<vector<int>> e(n);
for (int i = 0; i < n - 1; i++) {
int u, v;
cin >> u >> v;
u--;
v--;
e[u].push_back(v);
e[v].push_back(u);
}
vector<int> que(1), d(n, -1), f(n);
d[0] = 0;
f[0] = 1;
for (int i = 0; i < (int) que.size(); i++) {
int v = que[i];
for (int u : e[v]) {
if (d[u] == -1) {
f[d[u] = d[v] + 1] += 1;
que.push_back(u);
}
}
}
assert((int) que.size() == n);
for (int i = 1; i < n; i++) {
f[i] += f[i - 1];
}
while (q--) {
int x;
cin >> x;
cout << f[min(x, n - 1)] << '\n';
}
}
return 0;
}