/*
* Author: Md. Mahfuzur Rahman
* Purpose: Competitive Programming
*/
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pb push_back
#define endl '\n'
#define nl cout << endl
#define ff first
#define ss second
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define srt(v) sort(v.begin(),v.end())
#define pii pair<int, int>
#define pll pair<long,long>
#define FAST_IO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define minheap priority_queue<long long, vector<long long>, greater<long long>>
#define maxheap priority_queue<long long, vector<long long>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds; // find_by_order, order_of_key
template <typename... T>
void read(T&... args){((cin>>args), ...);}
template <typename... T>
void write(T... args){((cout<<args<<" "), ...);}
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const double EPS = 1e-9;
const int MAX = 1e6;
void solve(int tc)
{
ll n,k;cin>>n>>k;
string s;cin>>s;
// ll ct=0;
// for(auto x:s){
// if(x=='1')ct++;
// }
// if(k>=n/2){
// cout<<ct<<endl;
// return;
// }
vector<ll>cons;
ll ct=0;
ll start=0;
for(ll i=0;i<n;i++)
{
if(start==0&&s[i]=='1'){
start=1;
ct++;
}
else if(start==1&&s[i]=='1'){
ct++;
}
else if(start==1&&s[i]=='0'){
start=0;
cons.push_back(ct);
ct=0;
}
}
if(ct){
cons.push_back(ct);
}
sort(all(cons));
reverse(all(cons));
cons.push_back(0);
// debug(cons);
ll ans=cons[0],sz=cons.size();;
for(ll i=1;i<=min(sz+1,k);i++){
ans+=cons[i];
}
cout<<ans<<endl;
}
int main()
{
FAST_IO;
int t = 1;
int tc=1;
cin >> t;
while (t--)
{
solve(tc++);
}
return 0;
}