def solveA(n, ip):
    '''  RPI = 0.25 * WP + 0.50 * OWP + 0.25 * OOWP '''
    res = 0

    wp = [0 for i in range(n)]
    owp = [[2 for i in range(n)] for j in range(n)]
    for i, line in enumerate(ip):
        loss = line.count("0")
        win = line.count("1")
        total = win + loss
        wp[i] = win / total
        for j, c in enumerate(line):
            if c == "0":
                owp[i][j] = win / (total - 1)
            elif c == "1":
                owp[i][j] = (win - 1) / (total - 1)

    owpf = [0 for i in range(n)]
    for i, line in enumerate(ip):
        cnt = 0
        s = 0
        for j, c in enumerate(line):
            if c != ".":
                cnt = cnt + 1
                s = s + owp[j][i]
        owpf[i] = s / cnt if cnt > 0 else 0

    oowp = [0 for i in range(n)]
    for i, line in enumerate(ip):
        cnt = 0
        s = 0
        for j, c in enumerate(line):
            if c != ".":
                cnt = cnt + 1
                s = s + owpf[j]
        oowp[i] = s / cnt if cnt > 0 else 0

    rpi = lambda x: 0.25 * wp[x] + 0.5 * owpf[x] + 0.25 * oowp[x]

    return [rpi(i) for i in range(n)]

if __name__ == "__main__":
    t = int(input())
    for ti in range(1, t + 1):
        n = int(input())
        ip = []
        for ni in range(n):
            line = input().strip()
            ip.append(line)

        res = solveA(n, ip)
        print("Case #{0}:".format(ti))
        for l in res:
            print(l)
