#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define f first
#define s second
using namespace std;
int main(){
// freopen("input.txt", "r", stdin);
// freopen("output.txt", "w", stdout);
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int t;
cin >> t;
while (t--){
ll n, k;
string s;
cin >> n >> k >> s;
vector<ll> a;
while (!s.empty()){
while (!s.empty() && s.back() == '0') s.pop_back();
int c = 0;
while (!s.empty() && s.back() == '1') c++, s.pop_back();
if (c) a.push_back(c);
}
if (a.empty()){
cout << 0 << endl;
continue;
}
sort(a.rbegin(), a.rend());
ll cur = a[0];
ll m = a.size();
for (int i = 1; i < min(m, k); i++){
cur += a[i];
}
cout << cur << endl;
}
}