#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
ll tc; cin >> tc;
while(tc--){
ll n, m; cin >> n >> m;
string s; cin >> s;
ll sum = 0, f= 0;
vector < ll > ache;
for(ll i = 0; i < n; i++){
if(s[i] == s[i+1] && s[i] == '1')
{
sum++;
}
else if( s[i] == '1'){
sum++;
ache.push_back(sum);
sum = 0;
}
}
sort(ache.rbegin(),ache.rend());
if(ache.size())
{ll ans = ache[0];
ll q = ache.size();
for(ll i = 1; i <= min(m , q - 1); i++){
//cout << ache[i] << " ";
ans += ache[i];
}
cout << ans << '\n';}
else
cout << "0\n";
}
return 0;
}