Crazy Rows (Small)

No attempts yetTime limit5sMemory limit512 MB

Problem

You are given an N×NN \times N matrix whose entries are 0 and 1. You can swap any two adjacent rows of the matrix.

Your goal is to have every 1 on the main diagonal or below it. That is, for each XX with 1XN1 \le X \le N, row XX must contain no 1 to the right of column XX.

Report the minimum number of row swaps needed to reach the goal.

Input

The first line contains the number of test cases, TT. TT test cases follow.

The first line of each test case contains one integer NN. Each of the next NN lines contains NN characters. Each character is either 0 or 1.

Limits

  • 1T601 \le T \le 60
  • 1N81 \le N \le 8

Output

For each test case, print one line in the form

Case #X: K

where XX is the test case number starting from 1, and KK is the minimum number of row swaps needed to have every 1 on the main diagonal or below it.

Every test case has a solution.