import numpy as np


def preprocessAnswers(answers):
    for i in range(len(answers)):
        answers[i] = [ int(c) for c in answers[i] ]
    return np.array(answers)


def questionLevel(answers):
    # difficulty of question = 1 - probability to be correct
    return (1 - answers.sum(axis = 0) / answers.shape[0])


def studentLevel(answers):
    # student skill = probability of correct answer
    return (answers.sum(axis = 1) / answers.shape[1])


def detect(answers):
    q_estimated = questionLevel(answers)
    s_estimated = studentLevel(answers)

    # cheater inflates skill thus failing on supposedly easy questions
    p_diff = s_estimated[..., None] - q_estimated
    # students with highest number of unlikely wrong answers cheats
    i_cheater = 0
    p_cheater = 0
    for i in range(p_diff.shape[0]):
        p_i = p_diff[i,:]
        p_i_false_answers = p_i * (1 - answers[i,:])
        p_unlikely = p_i_false_answers[p_i_false_answers > 0]
        if p_unlikely.sum() > p_cheater:
            p_cheater = p_unlikely.sum()
            i_cheater = i+1
    return i_cheater


def play():
    cases = int(input())
    p = int(input())
    for i in range(cases):
        answers = []
        for _ in range(100):
            answers.append(input())
        answers_np = preprocessAnswers(answers)
        cheater = detect(answers_np)
        print('Case #{}: {}'.format(i+1, cheater))


play()