// Arup Guha
// 4/3/2020
// Solution to 2020 Code Jam Qualification Round Question A: Vestigium
// Written in Contest

import java.util.*;

public class a {

	public static void main(String[] args) {
	
		Scanner stdin = new Scanner(System.in);
		int nC = stdin.nextInt();
		
		// Process cases.
		for (int loop=1; loop<=nC; loop++) {
		
			int n = stdin.nextInt();
			int[][] g = new int[n][n];
			
			// Read in.
			for (int i=0; i<n; i++) 
				for (int j=0; j<n; j++)
					g[i][j] = stdin.nextInt();
					
			// Get trace.
			int trace = 0;
			for (int i=0; i<n; i++) trace += g[i][i];
			
			// See rows with repeats.
			int sameRow = 0;
			for (int i=0; i<n; i++) {
				
				// Just use a frequency table. All vals in between 1 and n.
				int[] freq = new int[n];
				boolean ok = true;
				
				// Add the frequency. If anything hits 2, this row doesn't work.
				for (int j=0; j<n; j++) {
					freq[g[i][j]-1]++;
					if (freq[g[i][j]-1] > 1) ok = false;
				}
				
				// Update sameRow count if necessary.
				if (!ok) sameRow++;
			}
				
			// And columns - flip loop order.
			int sameCol= 0;
			for (int j=0; j<n; j++) {
				int[] freq = new int[n];
				boolean ok = true;
				for (int i=0; i<n; i++) {
					freq[g[i][j]-1]++;
					if (freq[g[i][j]-1] > 1) ok = false;
				}
				if (!ok) sameCol++;
			}

			// Ta da!
			System.out.println("Case #"+loop+": "+trace+" "+sameRow+" "+sameCol);
		}
	}
}