import java.util.*;import java.io.*;
public class Main {
public static void main(String[] args) {
try {
FastReader in = new FastReader();
FastWriter out = new FastWriter();
int testcases = 1; testcases = in.nextInt();
while (testcases-- > 0) {
int siz = in.nextInt();
int ops = in.nextInt();
char[] word = in.next().toCharArray();
PriorityQueue<Long> pq = new PriorityQueue<>(Comparator.reverseOrder());
int curr = 0;
for (char c : word) {
if (c == '1') {
curr++;
} else {
if(curr != 0) pq.add((long) curr);
curr = 0;
}
}
if(curr != 0) pq.add((long) curr);
// out.print(pq);
while(pq.size() > 1 && ops > 0) {
long first = pq.poll();
long second = pq.isEmpty() ? 0 : pq.poll();
pq.offer(first+second);
ops--;
}
out.println(pq.peek());
}
out.close();
} catch (Exception e) {
e.printStackTrace();
return;
}
}/* <Fast---reader> */ static class FastReader { BufferedReader br; StringTokenizer st; public FastReader() { br = new BufferedReader(new InputStreamReader(System.in)); } String next() { while (st == null || !st.hasMoreTokens()) { try { st = new StringTokenizer(br.readLine()); } catch (Exception e) { e.printStackTrace(); } } return st.nextToken(); } int nextInt() { return Integer.parseInt(next()); } long nextLong() { return Long.parseLong(next()); } double nextDouble() { return Double.parseDouble(next()); } String nextLine() { String str = ""; try { str = br.readLine().trim(); } catch (Exception e) { e.printStackTrace(); } return str; } }
/* <Fast---writer> */ static class FastWriter { private final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); public void print(Object object) throws IOException { bw.append("" + object); } public void println() throws IOException { bw.append("\n"); } public void println(Object object) throws IOException { print(object); bw.append("\n"); } public void close() throws IOException { bw.close(); } }
}