// In the name of Allah the merciful.
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define endl '\n'
#define efficient() ios_base::sync_with_stdio(0); cin.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return abs(a) * ( abs(b) / gcd ( a, b ) ); }
int dx[] = {+1, -1, 0, 0, +1, +1, -1, -1};
int dy[] = {0, 0, -1, +1, +1, -1, +1, -1};
const ll mod = 1e9 + 7; // 1000000007;
const double PI = 3.14159265358979323846;
const double eps = 1e-9; // if (abs(a-b) < 1e-9) {a and b are equal}
/*---------------------------------------------------------------------------------------------------------------*/
void solve()
{
int n, k; cin >> n >> k;
string s; cin >> s;
vector<int> cons_one;
int cnt = 0;
for (int i = 0; i < n; i++) {
if (s[i] == '1') cnt++;
else {
if (cnt) cons_one.push_back(cnt);
cnt = 0;
}
}
if (cnt) cons_one.push_back(cnt);
sort(cons_one.begin(), cons_one.end(), greater<int>());
int ans = 0;
for (int i = 0; i < min(k + 1, (int)cons_one.size()); i++) {
ans += cons_one[i];
}
cout << ans << endl;
}
int main(void) {
efficient();
int t = 1;
cin >> t;
for (int tc = 1; tc <= t; tc++) {
// cout << "Case " << tc << ": ";
solve();
}
return 0;
// Every problem has its weakness.
// This problem's weakness is...the existence of me!
}