import sys
def main():
input = sys.stdin.read().split()
idx = 0
T = int(input[idx])
idx += 1
for _ in range(T):
N, K = int(input[idx]), int(input[idx+1])
idx += 2
S = input[idx]
idx += 1
# Split into runs
runs = []
if N == 0:
print(0)
continue
prev = S[0]
count = 1
for c in S[1:]:
if c == prev:
count += 1
else:
runs.append((prev, count))
prev = c
count = 1
runs.append((prev, count))
# Extract 1s groups
ones = [length for char, length in runs if char == '1']
if not ones:
print(0)
continue
m = len(ones)
B = m - 1
if K >= B:
print(sum(ones))
else:
window_size = K + 1
current_sum = sum(ones[:window_size])
max_sum = current_sum
for i in range(window_size, m):
current_sum += ones[i] - ones[i - window_size]
if current_sum > max_sum:
max_sum = current_sum
print(max_sum)
if __name__ == '__main__':
main()