#include <bits/stdc++.h>
using namespace std;
int maxConsecutiveOnes(string S, int K) {
int N = S.length();
vector<int> groups;
int count = 0;
for (char c : S) {
if (c == '1') {
count++;
} else {
if (count > 0) {
groups.push_back(count);
count = 0;
}
}
}
if (count > 0) {
groups.push_back(count);
}
if (groups.empty()) {
return 0;
}
int maxLen = 0;
int left = 0;
int right = 0;
int zeroCount = 0;
while (right < groups.size()) {
if (right > 0) {
zeroCount++;
}
while (zeroCount > K) {
if (left < right) {
zeroCount--;
left++;
} else {
break;
}
}
int currentLen = 0;
for (int i = left; i <= right; i++) {
currentLen += groups[i];
}
maxLen = max(maxLen, currentLen);
right++;
}
return maxLen;
}
int main() {
int t;
cin >> t;
while(t--) {
int siz, k;
string s;
cin >> siz >> k;
cin >> s;
cout << maxConsecutiveOnes(s, k) << endl;
}
return 0;
}