#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 ;
}
I2luY2x1ZGU8Yml0cy9zdGRjKysuaD4KI2luY2x1ZGU8ZXh0L3BiX2RzL2Fzc29jX2NvbnRhaW5lci5ocHA+CnVzaW5nIG5hbWVzcGFjZSBzdGQ7CiNkZWZpbmUgbW9kIChsb25nIGxvbmcgaW50KSgxZTkrNykKdXNpbmcgbmFtZXNwYWNlIF9fZ251X3BiZHM7CnR5cGVkZWYgbG9uZyBsb25nIGludCBsbDsKdHlwZWRlZiB0cmVlPGxsLCBudWxsX3R5cGUsIGxlc3M8bGw+LCByYl90cmVlX3RhZywKICAgICAgICAgICAgIHRyZWVfb3JkZXJfc3RhdGlzdGljc19ub2RlX3VwZGF0ZT4KICAgIGluZGV4ZWRfc2V0OwoKbGwgbixrOwpsbCB2YWxbNTAwMDA5XTsKdmVjdG9yPGxsPnZbNTAwMDA5XTsKbGwgZHBbMTAwMDA5XVsxMDFdOyAgICAgLy8gZHBbaV1bal0gc3RvcmVzIG51bWJlciBvZiB3YXlzIG9mIGdldHRpbmcgc2NvcmUgaiBmcm9tIHN1YnRyZWUgb2Ygbm9kZSBpIGluY2x1ZGluZyBub2RlIGkKbGwgdmlzWzUwMDAwOV07CmxsIHN1Yls1MDAwMDldOwpsbCBwYXJbNTAwMDA5XTsKCnZvaWQgZGZzKGxsIG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