// Arup Guha
// 4/1/2021
// Solution to 2021 Code Jam Qualifying Question: Cheating Detection (Small Only)

import java.util.*;

public class Solution {

	public static void main(String[] args) {

		// Get # of cases.
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		int p = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
		
			int[][] res = new int[100][10000];
			int[] totalSum = new int[100];
			for (int i=0; i<100; i++) {
				char[] line = stdin.next().toCharArray();
				for (int j=0; j<10000; j++) {
					res[i][j] = line[j] == '0' ? 0 : 1;
					totalSum[i] += res[i][j];
				}
			}
			
			// questions[i] will have the question numbers where i people answered correctly.
			ArrayList<Integer>[] questions = new ArrayList[101];
			for (int i=0; i<=100; i++) questions[i] = new ArrayList<Integer>();
			
			// Get which question is in which category.
			for (int j=0; j<10000; j++) {
				int sum = 0;
				for (int i=0; i<100; i++)
					sum = sum + res[i][j];
				questions[sum].add(j);
			}
			
			// Stores each person's average, correct and wrong questions in each category.
			// A category 7, is the set of questions for which 7 people got it correct.
			double[][] avg = new double[100][101];
			int[][] correct = new int[100][101];
			int[][] wrong = new int[100][101];
			
			// i is the person.
			for (int i=0; i<100; i++) {
			
				// j is the category.
				for (int j=0; j<=100; j++) {
				
					//
					int yes = 0;
					for (Integer z: questions[j])
						yes += res[i][z];
						
					avg[i][j] = 1.0*yes/questions[j].size();
					correct[i][j] = yes;
					wrong[i][j] = questions[j].size()-yes;
				}
			
			}
			
			// Max 1s after 0s > 50%
			int ans = 0, max = 0;
			for (int i=0; i<100; i++) {
				
				int curBad = wrong[i][100];
				int total = 0;
				for (int j=99; j>=0; j--) {
					total += correct[i][j]*curBad;
					curBad += wrong[i][j];
				}
				
				if (total > max && totalSum[i] > 5000) {
					ans = i;
					max = total;
				}
			}
			
			// Ta da!
			System.out.println("Case #"+loop+": "+(ans+1));			
		}
	}
	
	public static double solve(double[][] avg, int idx) {
	
		double sum = 0;
		for (int i=1; i<=50; i++) sum += avg[idx][i];
		double myavg = sum/50;
		
		double sumsq = 0;
		for (int i=1; i<=50; i++)
			sumsq += (avg[idx][i] - myavg)*(avg[idx][i] - myavg);
			
		return Math.sqrt(sumsq/50);
	
	}
	

}