#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define endme "\n";
#define ffprint(x) \
for (auto &i : x) \
{ \
cout << i << " "; \
} \
cout<<endme;
#define vectinput(x) for(auto &i : x) cin >> i;
#ifndef ONLINE_JUDGE
#include"Debug.cpp"
#endif
void solve(){
int n,m;
cin>>n>>m;
vector<int>dangerous(n);
vectinput(dangerous);
vector<vector<int>> tree(n);
for(int i=0;i<n-1;i++){
int a,b;
cin>>a>>b;
a--;
b--;
tree[a].push_back(b);
}
vector<int>streak(n),maxstreak(n);
queue<int>q;
q.push(0);
streak[0]=(dangerous[0]?1:0);
maxstreak[0]=streak[0];
int ans=0;
while(!q.empty()){
int top=q.front();
q.pop();
if(tree[top].empty() && (maxstreak[top]<=m)){
ans++;
}
for(auto node:tree[top]){
if(dangerous[node]){
streak[node]=streak[top]+1;
}else{
streak[node]=0;
}
maxstreak[node]=max(streak[node],maxstreak[top]);
q.push(node);
}
}
cout<<ans<<endme;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);
#ifndef ONLINE_JUDGE
freopen("0-InputFile/input.txt", "r", stdin);
freopen("0-InputFile/output.txt", "w", stdout);
#endif
int t;
cin>>t;
// t=1;
while (t--) {
solve();
}
return 0;
}
/*
reset_template.bat
%%%%%%%%+++*%@@@@@%%@%%%%%%%%%%%@@%%%%%%##**###%%%
%%%%%%%%#*#%@@@@@@@%%%%%#%%%@@@@@%####**####%%@@@@
%%%%%%%%##%@@@@@@@*+++++++++*#@@@@%####%%%%@@@@@@@
%%%%%%%%#%%@@@@@#++++++++++++@@@@@@@%%%@@@@@@@@@@@
@%#%%#%#%%%%%%*++++++++++++++*@@@@@@#++++++*######
%%%%%#%%%###++++++++++++++++++*#@@@#*******#******
#%%%%%%%%%%*+++++******+++++++++**++*##**+++***##%
%%#%%%%%@@*++++*%@@#*****#%#*++++++++++++**##%@@@%
%%%%%%%%%#+***#@@@#++*++*@@@#***+++++++*#%@@%##%%%
%%%%%%%%#**###%@@#+++++++#@@@#*#**++**##%#####%@@@
%%%%%%%%%**####%#++*##*++*@@@%###***#@@@@@%%%%@@@@
%%%%%%%%%#*#####**#@@@@@***%%%%%##*%@@@@@@@@%%@@%%
%%%%%%%%#%**######%%@@%##%%%%%%%##%@@@@@@@@@%#****
%@@%%%###@@%#%%%@%%@@@@@@@%%%%%%%@@@@@@@@@@@@%#**#
%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@###
%%%#%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%
%%%%%%%%%@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@%
*/