#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
using namespace std;
#define mod (long long int)(1e9+7)
using namespace __gnu_pbds;
typedef long long int ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,
             tree_order_statistics_node_update>
    indexed_set;

ll n,k;
ll val[500009];
vector<ll>v[500009];
ll dp[100009][101];     // dp[i][j] stores number of ways of getting score j from subtree of node i including node i
ll vis[500009];
ll sub[500009];
ll par[500009];

void dfs(ll node)
{

  vis[node]=1;
  for(auto child : v[node]){
  if(vis[child]==0){
   par[child]=node;
  dfs(child);
  sub[node]+=sub[child];
  }
  }

ll temp[101]={0};        // temporary array to store value of dp[node] array
if(val[node]==1)
temp[1]=1;     // if val[node]==1 we can get score 1 in 1 way without using any child(its subtree) of this node
else
temp[0]=1;   // if val[node]==0 we can get score 0 in 1 way without using ant child(its subtree) of this node

for(auto child : v[node])
{
  if(child!=par[node])
  {
     // taversing only upto  min(sub[node],(ll)100) because if size of subtree of node is less than 100(let x)
     // then we can not get score >x from this subtree and if  size of its subtree is greater than 100 we need to calculate upto 100 only
     // because k<=100

    for(ll i=min(sub[node],(ll)100);i>=0;i--)                 // traversing from backward to forward to avoid extra counting
    {
       for(ll j=0;j<=min(min(sub[child],(ll)100),i);j++){
       temp[i]=(temp[i]+ ((temp[i-j]*dp[child][j])%mod) )%mod;  // if we can get score i-j without using this child(its subtree) in (temp[i-j] / dp[node][i-j]) ways
       }                                                        // and we can get score j in dp[child][j] ways using this child then we can get score i
    }                                                           // in temp[i-j]*dp[chilc][j] ways using this child
  }
}

for(ll i=0;i<=min(sub[node],(ll)100);i++)
dp[node][i]=temp[i];



}



int main()
{
 ios_base::sync_with_stdio(false);
    cin.tie(NULL);

ll t=1;
cin>>t;
while(t--)
{

ll i;
cin>>n>>k;

for(i=1;i<=n;i++)
cin>>val[i];

for(i=0;i<n-1;i++)
{
  ll a,b;
   cin>>a>>b;
   v[a].push_back(b);
   v[b].push_back(a);
}
for(i=0;i<=n;i++)
{
  sub[i]=1;
  vis[i]=0;
  for(ll j=0;j<101;j++)
   dp[i][j]=0;
}
par[1]=0;

dfs(1);

ll ans=0;

for(i=1;i<=n;i++)
ans=(ans+dp[i][k])%mod;
cout<<ans<<endl;


for(i=0;i<=n;i++)
v[i].clear();

}
return 0;
}
