#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define f(i,n) for(ll i=0;i<n;i++)
#define m(a,b,c) max(a,max(b,c))
#define N ll n;cin >> n;
#define Nk ll n,k;cin >> n >> k;
#define A ll a[n];f(i,n) cin >> a[i];
#define FAST_IO ios_base::sync_with_stdio(false), cin.tie(nullptr);
#define YES cout<<"YES"<<endl;
#define NO cout<<"NO"<<endl;
#define S string s;cin>>s;
#define pb push_back
vector<vector<ll>> adj;
vector<bool> visited;
vector<ll> depth;
void dfs(ll node, ll d) {
visited[node] = true;
depth[node] = d;
for (ll neighbor : adj[node]) {
if (!visited[neighbor]) {
dfs(neighbor, d + 1);
}
}
}
int main()
{
FAST_IO;
ll t;
cin>>t;
while(t--)
{
N;
ll q;
cin>>q;
adj.resize(n + 1);
visited.resize(n + 1, false);
depth.resize(n + 1);
for (ll i = 1; i < n; ++i)
{
ll u, v;
cin >> u >> v;
adj[u].push_back(v);
adj[v].push_back(u);
}
dfs(1, 0);
ll p=pow(10,5);
ll tom[p+1]={0};
for(ll i=1;i<=n;i++)
{
tom[depth[i]]++;
}
ll c[p+1];
c[0]=1;
f(i,p+1)
{
c[i+1]=c[i]+tom[i+1];
}
f(i,q)
{
ll x;
cin>>x;
cout<<c[x]<<endl;
}
}
return 0;
}