#include <bits/stdc++.h>
#define nl cout<<'\n';
#define space cout<<' ';
#define print(s) cout<<s;
#define ll long long
#define all(x) (x).begin(), (x).end()
#define Point(x,y) setprecision((y))<<fixed<<(x)
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define Fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define dbg(x) cout<<"line " << __LINE__ << " says: " << #x << " = " << x << "\n";
#define printarry(a) for(auto it : a) cout<<it<<' ';
#define put_array(x,n) for (int i = 0; i < n; ++i) cin >> x[i];
using namespace std;
//-----------------------------------------------------------------------------------------------------------------------------------
// PRACTICE AND LEARN
//-----------------------------------------------------------------------------------------------------------------------------------
void test_case()
{
int n,k;
cin >> n >> k;
string s;
cin >> s;
std::vector<int> v;
int cnt = 0;
for (int i = 0; i < n ; ++i)
{
if(s[i]=='1')
{
cnt++;
}
else
{
v.push_back(cnt);
cnt=0;
}
}
v.push_back(cnt);
sort(v.rbegin(),v.rend());
long long ans = v[0];
int point = 1;
for (int i = 1; i <= k; ++i)
{
ans += v[point];
point++;
}
cout << ans ;
nl
return;
}
int32_t main()
{
Fast;
#ifdef NAYEEM
int start_time = clock();
int end_time = clock();
printf("Time = %.4f\n", (end_time - start_time + 0.0) / CLOCKS_PER_SEC);
#endif
int test_number = 1;
cin >> test_number;
while (test_number--)
{
test_case();
}
return 0;
}