Inversions Organize

아직 제출이 없습니다시간 제한20초메모리 제한1024 MB

문제

After the troubles with printing advertising for IO two years ago, the marketing team of the conference decided to use an interactive installation. It consists of a matrix of 2N2N rows and 2N2N columns of touchscreens. Each touchscreen can display either an uppercase I or an uppercase O. When one of the screens is touched, it switches the letter it displays to the one it was not displaying right before the touch occurred.

You are looking at one of those installations, and find it to be disorganized. You want to change some of the letters such that the top NN rows show the same number of letter I⁠'s as the bottom NN rows, and at the same time, the leftmost NN columns show the same number of letter I⁠'s in total as the rightmost NN columns.

For example, in the left picture above, N=2N=2. The top 22 rows show 33 letter I⁠'s in total, while the bottom 22 rows show 55. On the other hand, both the leftmost 22 columns and the rightmost 22 columns show 44 letter I⁠'s. By touching the two highlighted screens we can change the state to that shown in the right picture, which shows 44 letter I⁠'s in the top 22 columns and in the bottom 22 columns, and also maintains the balance between the left and right sides.

Given the state of the installation, can you find the minimum number of letter changes needed to achieve your organizational goal?

입력

The first line of the input gives the number of test cases, TTTT test cases follow. Each test case starts with a line containing a single integer NN, half the number of rows and columns of the matrix. Then, 2N2N lines follow. The ii-th of these contains a string of 2N2N characters C_i,1C_i,2C_i,2NC\_{i,1}C\_{i,2}\cdots C\_{i,2N}C_i,jC\_{i,j} is the letter currently displayed in the screen in the ii-th row and jj-th column of the matrix.

출력

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 1) and yy is the minimum number of touches required to make the installation simultaneously display the same number of letter I⁠'s in its top and bottom halves, and the same number of letter I⁠'s in its left and right halves.

제한

  • 1T1001≤T≤100.
  • C_i,jC\_{i,j} is either an uppercase I or an uppercase O, for all i,ji,j.

힌트

Sample Case #1 is the one explained in the statement. Not touching anything does not work, and a single touch would leave an odd number of letters I in total, so the result cannot be balanced. It is explained in the statement how it can be balanced with two touches (there are other ways).

In Sample Case #2, changing the top left corner to O leaves no letter I, so all halves have the same amount (00).

In Sample Case #3, the installation is already organized according to your requirements, so no touch is needed.