from collections import defaultdict

def readLine(line):
    return [ int(c) for c in line.split(' ') ]


def isArithmeticSeq(seq):
    return seq[1] - seq[0] == seq[2] - seq[1]


def solve(arr):
    arr[1].append(arr[1][-1])
    arr[1][1] = None
    count = 0

    if isArithmeticSeq(arr[0]): count += 1
    if isArithmeticSeq(arr[2]): count += 1
    if isArithmeticSeq([arr[i][0] for i in range(3)]): count += 1
    if isArithmeticSeq([arr[i][2] for i in range(3)]): count += 1

    # potential values to get arithmethic sequences
    xH = arr[1][2] - (arr[1][2] - arr[1][0]) / 2
    xV = arr[2][1] - (arr[2][1] - arr[0][1]) / 2
    xD1 = arr[2][2] - (arr[2][2] - arr[0][0]) / 2
    xD2 = arr[2][0] - (arr[2][0] - arr[0][2]) / 2

    xScore = defaultdict(int)
    for x in [xH, xV, xD1, xD2]:
        if int(x) == x: xScore[int(x)] += 1

    xScoreMax = 0
    topX = None
    for x in xScore:
        xScoreMax = max(xScoreMax, xScore[x])

    return count + xScoreMax


def play():
    cases = int(input())
    for i in range(cases):
        arr = []
        for _ in range(3):
            arr.append(readLine(input()))
        output = solve(arr)
        print('Case #{}: {}'.format(i + 1, output))


play()
from collections import defaultdict

def readLine(line):
    return [ int(c) for c in line.split(' ') ]


def isArithmeticSeq(seq):
    return seq[1] - seq[0] == seq[2] - seq[1]


def solve(arr):
    arr[1].append(arr[1][-1])
    arr[1][1] = None
    count = 0

    if isArithmeticSeq(arr[0]): count += 1
    if isArithmeticSeq(arr[2]): count += 1
    if isArithmeticSeq([arr[i][0] for i in range(3)]): count += 1
    if isArithmeticSeq([arr[i][2] for i in range(3)]): count += 1

    # potential values to get arithmethic sequences
    xH = arr[1][2] - (arr[1][2] - arr[1][0]) / 2
    xV = arr[2][1] - (arr[2][1] - arr[0][1]) / 2
    xD1 = arr[2][2] - (arr[2][2] - arr[0][0]) / 2
    xD2 = arr[2][0] - (arr[2][0] - arr[0][2]) / 2

    xScore = defaultdict(int)
    for x in [xH, xV, xD1, xD2]:
        if int(x) == x: xScore[int(x)] += 1

    xScoreMax = 0
    topX = None
    for x in xScore:
        xScoreMax = max(xScoreMax, xScore[x])

    return count + xScoreMax


def play():
    cases = int(input())
    for i in range(cases):
        arr = []
        for _ in range(3):
            arr.append(readLine(input()))
        output = solve(arr)
        print('Case #{}: {}'.format(i + 1, output))


play()
# potential values to get arithmethic sequences #{}: {}'.format(i + 1, output))