#include <bits/stdc++.h>
using namespace std;
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);
using ll = long long;
int main() {
FAST;
int tc = 1, ti;
cin >> tc;
for (ti = 1; ti <= tc; ++ti) {
int n, k, i, j, ans;
cin >> n >> k;
string s;
cin >> s;
vector<int> a;
for (i = 0; i < n; ++i) {
if (s[i] == '0') continue;
for (j = i+1; j < n; ++j) {
if (s[j] == '0') break;
}
a.push_back(j-i);
i = j-1;
}
sort(a.rbegin(), a.rend());
ans = 0;
for (i = 0; i < min(k+1, (int)a.size()); ++i) {
ans += a[i];
}
cout << ans << "\n";
}
return 0;
}