Kill the Chitauris

5

1 votes
Easy
Problem

Chitauris (Thanos' Army ) have led down a special trap for Avengers. They have created multiple mirror images of their army to confuse Avengers.
Their army is organised in the form of some matrix C . Let's assume the matrix C of size x × y, let's determine the operation of mirroring matrix C. The mirroring of matrix C is a 2x × y matrix D which has the following properties:
the upper half of matrix D (rows with numbers from 1 to x) exactly matches C;
the lower half of matrix D (rows with numbers from x + 1 to 2x) is symmetric to the upper one; the symmetry line is the line that separates two halves (the line that goes in the middle, between rows x and x + 1).
You are given the visible structutre of Chitauris in form of n × m matrix A. Avengers want you to find matrix C, that has been transformed into matrix A by Chitauris through several (possibly zero) mirrorings on it. If we kill the original army C then all the mirrored ones will die as well. So, you need to find the minimum number of rows that such matrix (C) can contain.

Input
First line of the test case contain number of test cases t .
for each test case we have:
line 1 contain n and m which are dimensions of matrix A.
next n lines contains m integers - the elements of matrix A ,i.e. the ith line contain integers A[i][0]....A[i][m] - ith row of matrix A.

Ouput
Output a single integer for each test case , denoting answer to the problem -the minimum number of rows that such matrix (C) can contain.

Constraints 
1<=n,m<=100
0<=A[i][j]<=1

Time Limit: 5
Memory Limit: 256
Source Limit:
Editor Image

?