#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
// Function to find the maximum number of consecutive 1s that can be achieved
int maximizeConsecutiveOnes(const string &S, int K) {
int n = S.size();
int maxOnes = 0;
int zeroCount = 0;
int left = 0;
// Sliding window approach
for (int right = 0; right < n; ++right) {
// Count zeros in the current window
if (S[right] == '0') {
++zeroCount;
}
// If zeroCount exceeds K, move the left pointer to maintain the constraint
while (zeroCount > K) {
if (S[left] == '0') {
--zeroCount;
}
++left;
}
// Update the maximum number of consecutive 1s
maxOnes = max(maxOnes, right - left + 1);
}
return maxOnes;
}
int main() {
ios::sync_with_stdio(false);
cin.tie(nullptr);
int T;
cin >> T;
while (T--) {
int N, K;
cin >> N >> K;
string S;
cin >> S;
cout << maximizeConsecutiveOnes(S, K) << "\n";
}
return 0;
}