Under construction

Still being built. Things may change

Vestigium

Interview

Time limit20sMemory limit1024 MB

Summary
Given an N by N matrix with values from 1 to N, find its trace and count the rows and columns that contain a repeated value.
Level

Easy2 of 10

Topics
Array, Implementation
Solved
No attempts yet

Problem

Vestigium means 'trace' in Latin. In this problem we work with Latin squares and matrix traces.

The trace of a square matrix is the sum of the values on the main diagonal, which runs from the upper left to the lower right.

An N×NN \times N matrix is a Latin square if each cell contains one of NN different values, and no value is repeated within a row or a column. This problem deals only with natural Latin squares, in which the NN values are the integers from 1 to NN.

Given a matrix that contains only integers from 1 to NN, compute its trace and check whether it is a natural Latin square. Instead of only reporting whether it is one, count the rows and the columns that contain repeated values.

Input

The first line contains the number of test cases TT. Then TT test cases follow. Each test case starts with a line containing a single integer NN, the size of the matrix. Then NN lines follow. The ii-th of these lines contains NN integers Mi,1,Mi,2,…,Mi,NM_{i,1}, M_{i,2}, \ldots, M_{i,N}, where Mi,jM_{i,j} is the integer in row ii and column jj.

Output

For each test case, output one line containing Case #x: k r c. Here xx is the test case number starting from 1, kk is the trace of the matrix, rr is the number of rows that contain repeated elements, and cc is the number of columns that contain repeated elements.

Limits

  • 1≤T≤1001 \le T \le 100.
  • 2≤N≤1002 \le N \le 100.
  • 1≤Mi,j≤N1 \le M_{i,j} \le N for all i,ji, j.

Hints

In Sample Case #1, the input is a natural Latin square, so no row or column has repeated elements. All four values on the main diagonal are 1, so the trace is 4.

In Sample Case #2, every row and every column has repeated elements. A row or column with repeated elements is counted only once, no matter how many values repeat or how often. Some integers from 1 to NN may also be absent from the input.

In Sample Case #3, the leftmost and rightmost columns have repeated elements.

Examples1

  1. Example 1

    Input
    3
    4
    1 2 3 4
    2 1 4 3
    3 4 1 2
    4 3 2 1
    4
    2 2 2 2
    2 3 2 3
    2 2 2 3
    2 2 2 2
    3
    2 1 3
    1 3 2
    1 2 3
    
    Expected output
    Case #1: 4 0 0
    Case #2: 9 4 4
    Case #3: 8 0 2