#include <bits/stdc++.h> // All praise is due to Allah alone, and peace and blessings be
using namespace std; // upon him, after whom there is no other Prophet.
int32_t main() {
cin.tie(0)->sync_with_stdio(false);
function<void()> Test_Case = [&]() {
int n, k; cin >> n >> k;
string s; cin >> s;
priority_queue<int> p;
for(int i = 0, j, cnt; i < n; i = j) {
cnt = 1, j = i + 1;
for( ; j < n; j++) {
if(s[i] == s[j]) {cnt++;}
else break;
}
if(s[i] == '1') {
p.push(cnt);
}
}
int ans = 0;
while(p.size() and k >= 0) {
ans += p.top(); p.pop();
k--;
}
cout << ans << '\n';
};
int32_t Case = 1; cin >> Case;
for (int T = 1; T <= Case; T++) {
Test_Case();
}
return 0;
}