#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
using namespace std;
int32_t main() {
ios_base :: sync_with_stdio(0);
cin.tie(0); cout.tie(0);
int t;
cin >> t;
while (t--) {
ll n, k;
cin >> n >> k;
string s;
cin >> s;
int conseq_one = 0, one = 0, ans_conseq = 0;
vector<int> store;
for (int i = 0; i < n; i++) {
conseq_one = 0;
while (s[i] == '1' && i < n) {
conseq_one++;
i++;
}
store.push_back(conseq_one);
//ans_conseq = max(ans_conseq, conseq_one);
}
int arr_size = store.size();
sort(store.rbegin(), store.rend());
int ans = store[0];
for (int i = 1; i < arr_size && i <= k; i++) {
ans += store[i];
}
cout << ans << endl;
/* int other_ones = one - ans_conseq;
int non_conseq = abs(one - ans_conseq);
if (other_ones <= k) cout << non_conseq + other_ones << endl;
else {
if (other_ones >= k) cout << ans_conseq + k << endl;
else cout << ans_conseq + other_ones << endl;
}*/
}
return 0;
}