#include<bits/stdc++.h>
#define endl '\n'
using namespace std;
using ll = long long;
void solve() {
ll n, k;
cin >> n >> k;
string s1;
cin >> s1;
vector<ll> con1;
for(int i = 0; i < n; ) {
int j = i;
while(j < n && s1[j] == '1') ++j;
if(j - i > 0) con1.push_back(j - i);
while(j < n && s1[j] == '0') ++j;
i = j;
}
sort(con1.begin(), con1.end());
ll ans = 0;
k++;
while(k-- && con1.size()) {
ans += con1.back();
con1.pop_back();
}
cout << ans << endl;
return;
}
int main() {
ios::sync_with_stdio(false); cin.tie(0);
int tc = 1;
cin >> tc;
for (int t = 1; t <= tc; t++) {
// cout << "Case " << t << ": ";
solve();
}
return 0;
}