/**
* written by Binoy Barman .
**/
#include<bits/stdc++.h>
using namespace std;
#define nl '\n'
#define all(v) v.begin(), v.end()
#define Too_Many_Jobs int tts, tc = 1; cin >> tts; hell: while(tts--)
#define Dark_Lord_Binoy ios_base::sync_with_stdio(false); cin.tie(NULL);
#ifdef LOCAL
#include "unravel.hpp"
#else
#define dbg(...) 42
#endif
#define ll long long
const int N = 1e5 + 5;
int n, q, x, u, v;
vector<int> g[N];
bool vis[N];
int lvl[N], ans[N];
void bfs(int start) {
memset(vis, 0, sizeof vis);
memset(lvl, 0, sizeof lvl);
memset(ans, 0, sizeof ans);
queue<int> q;
vis[start] = 1;
lvl[start] = 0;
ans[0]++;
q.push(start);
while (!q.empty()) {
int current = q.front();
q.pop();
for (const auto& neighbor : g[current]) {
if (!vis[neighbor]) {
vis[neighbor] = 1;
lvl[neighbor] = lvl[current] + 1;
ans[lvl[neighbor]]++;
q.push(neighbor);
}
}
}
}
int32_t main() {
Dark_Lord_Binoy
#ifdef LOCAL
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
Too_Many_Jobs {
cin >> n >> q;
for (int i = 1; i < n; i++) {
cin >> u >> v;
g[u].push_back(v);
g[v].push_back(u);
}
bfs(1);
for (int i = 1; i < N; i++) {
ans[i] += ans[i - 1];
}
while(q--) {
cin >> x;
cout << ans[x] << nl;
}
for (int i = 0; i <= n; i++) {
g[i].clear();
}
}
return 0;
}