#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long int
#define endl '\n'
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
#define all(v) v.begin(), v.end()
#define pb push_back //
#define mp make_pair
#define fi first //
#define se second //
#define yes cout << "YES" << endl //
#define no cout << "NO" << endl //
#define M 1000000007 // 1e9+7
#define gcd(a, b) __gcd(a, b) //
#define lcm(a, b) a *b / gcd(a, b) //
#define memz(a) memset(a, 0, sizeof(a)) //
#define memn(a) memset(a, -1, sizeof(a)) //
ll fact[5001];
ll binary(ll a,ll b)
{
ll ans=1;
while(b)
{
if(b%2)ans=(ans*a)%M;
a=(a*a)%M;
b/=2;
}
return ans;
}
ll ncr(ll n,ll r)
{
return (fact[n]*binary((fact[r]*fact[n-r])%M,M-2))%M;
}
int main()
{
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
fact[0]=1;
for(int i=1;i<=5000;i++)
{
fact[i]=(fact[i-1]*i)%M;
}
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
ll tst;
cin>>tst;
for(ll test=1;test<=tst;test++)
{
//cout<<"Case "<<test<<": ";
ll n,k;
cin>>n>>k;
ll ans=0;
ll sum=0;
for(int i=0;i<n;i++)
{
ll t;
cin>>t;
sum+=t;
}
ll z=(n-sum);
z=(z*(z+1))/2;
z++;
for(int i=k;i<=sum;i++)
{
if(i!=sum)ans=(ans+(ncr(sum,i)*z)%M)%M;
if(i==sum)ans=(ans+(ncr(sum,i)*(z-1))%M+M)%M;
}
cout<<ans<<endl;
}
}