#include <bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define endl '\n'
#define Endl '\n'
using namespace std;
const int N = 2e5 + 5;
int tc, n, m;
ll Ans[N];
vector<int> x[N];
void dfs(int node, int par, int cnt) {
Ans[cnt]++;
for (auto i : x[node]) {
if (i == par) {
continue;
}
dfs(i, node, cnt + 1);
}
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0); // cout.tie(0);
cin >> tc;
while (tc--) {
cin >> n >> m;
for (int i = 0; i < n + 5; i++) {
x[i].clear();
Ans[i] = 0;
}
for (int i = 0; i < n - 1; i++) {
int a, b;
cin >> a >> b;
x[a].push_back(b);
x[b].push_back(a);
}
dfs(1, -1, 0);
for (int i = 1; i <= n; i++) {
Ans[i] += Ans[i - 1];
}
while (m--) {
int x;
cin >> x;
cout << Ans[x] << endl;
}
}
return 0;
}