#include <bits/stdc++.h>
using namespace std;
using ll = long long;
void solve(int T) {
int n, k; cin >> n >> k;
string s; cin >> s;
s.push_back('0');
priority_queue<int> pq;
int cnt = 0;
for(auto c : s) {
if(c == '1') cnt++;
else {
pq.push(cnt);
cnt = 0;
}
}
ll ans = 0;
if(!pq.empty()) {
ans = pq.top();
pq.pop();
while(!pq.empty() && k) {
ans += pq.top();
pq.pop();
k--;
}
}
cout << ans << "\n";
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
#ifdef MYPC
cout << "==== OUTPUT ====\n";
#endif
int t; cin >> t;
for(int i = 1; i <= t; i++) {
solve(i);
}
}