You are given an n \times m matrix .
Each integer from to n\cdot m appears in exactly once.
For an integer (1 \le x \le n\cdot m), define its correct position as it's position in the origin matrix
We call Good if it is currently located at it's correct position .
In one move, you may choose any column and cyclically shift it upwards by any number of positions (including performing zero moves overall).
A column is called Perfect if there exists a sequence of moves such that, in the final matrix, every element in column is in its correct position (equivalently, every element in column satisfies \text{col}(x)=j and is placed in row ).
Determine the number of Perfect columns.
For example :
Column is already Perfect. If we cyclically shift column upwards by , we get
and then shifting column upwards by gives
Now every column is Perfect.
The first line contains a single integer (1 \le t \le 10^4) — the number of test cases.
The first line of each test case contains two integers and (1 \le n\cdot m \le 2\cdot 10^5) — the number of rows and the number of columns, respectively.
The next lines each contain integers M_{i,1}, M_{i,2}, \ldots, M_{i,m} (1 \le M_{i,j} \le n\cdot m). The -th of these lines describes the -th row of the matrix .
It is guaranteed that the sum of n\cdot m over all test cases does not exceed 2\cdot 10^5.
For each test case, output a single integer — the number of columns that can be made perfect after performing any number of upward cyclic shifts.
Example 1
In the first test case, no operations are needed: every column of the matrix is already Perfect.
In the second test case, it can be shown that no matter which operations you apply, you cannot make even a single column Perfect.
In the third test case, the entire matrix can be made Perfect using the following operations:
Cyclically shift column upwards by :
Cyclically shift column upwards by :
Now every element is in its correct position, so the whole matrix is Perfect.
Subtask ( points) : (1 \le n,m \le 100)
Subtask ( points) : No additional constraints.