#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);
int tc; cin >> tc;
while(tc--){
int n, m; cin >> n >> m;
string s; cin >> s;
int sum = 0, f= 0;
vector < int > ache;
for(int 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());
ll ans = ache[0];
int q = ache.size();
for(int i = 1; i <= min(m , q - 1); i++){
//cout << ache[i] << " ";
ans += ache[i];
}
cout << ans << '\n';
}
return 0;
}