#include <iostream>
#include <vector>
#include <queue>
#include <cstring>
using namespace std;
const int MAX_N = 100005; // Maximum number of nodes in the tree
vector<int> adj[MAX_N]; // Adjacency list to represent the tree
int distances[MAX_N]; // To store distances of nodes from the root
void bfs(int root) {
queue<int> q;
q.push(root);
memset(distances, -1, sizeof(distances));
distances[root] = 0;
while (!q.empty()) {
int node = q.front();
q.pop();
for (int child : adj[node]) {
if (distances[child] == -1) {
distances[child] = distances[node] + 1;
q.push(child);
}
}
}
}
int main() {
int T;
cin >> T;
while (T--) {
int N, Q;
cin >> N >> Q;
// Clearing the adjacency list for each test case
for (int i = 1; i <= N; ++i) {
adj[i].clear();
}
// Constructing the tree
for (int i = 0; i < N - 1; ++i) {
int U, V;
cin >> U >> V;
adj[U].push_back(V);
adj[V].push_back(U);
}
bfs(1); // Start BFS from the root node (node 1)
// Processing queries
for (int i = 0; i < Q; ++i) {
int X;
cin >> X;
int count = 0;
for (int j = 1; j <= N; ++j) {
if (distances[j] <= X) {
count++;
}
}
cout << count << endl;
}
}
return 0;
}