


The first line of input contains an integer 'T', denoting the number of test cases.
The first line of each test case contains a single integer 'N' size of the input matrix ‘MAT’.
Each of the next 'N' contains an integer ‘K’ number of cells in the current row followed by ‘K’ integers cell sizes.
For each test case, print the minimum number of crossed cells after drawing the line.
Output for each test case will be printed in a separate line.
You don't need to print anything. It has already been taken care of. Just implement the given function.
1 <= ‘T’ <= 10
1 <= 'N' <= 10^2
1 <= ‘K’ <= ‘N’
1 <= 'MAT[i]' <= ‘N’
1 <= SUM('MAT[i]') <= 'N'
SUM('MAT[i]') is same for each row
Time Limit : 1 sec
We know the width of the matrix, also we can precalculate how many cells are ending at the ith position from the left.
So, we can iterate over the cells first and store a number of cells ending at the particular position in the hashmap array.
Again we will iterate over the width of the matrix, and for each length, we will find the number of cells that will be crossover when we draw the line from this length. We will take the minimum of all such lines.
Algorithm: