#C614. Taco Grid Zero Operations

    ID: 49867 Type: Default 1000ms 256MiB

Taco Grid Zero Operations

Taco Grid Zero Operations

You are given several test cases. In each test case, you are provided with a grid of n rows and m columns. The grid contains integer values. Your task is to determine the minimum number of operations required to make all elements of the grid equal to zero.

The operation is defined as follows: if there is at least one nonzero element in the grid, the minimum number of operations needed is \(\min(n, m)\). Otherwise, if the grid is already filled with zeros, the answer is 0.

Note: \(\min(n, m)\) denotes the minimum of \(n\) and \(m\). For example, if \(n = 2\) and \(m = 3\), then \(\min(n, m) = 2\).

inputFormat

The first line contains a single integer \(T\) representing the number of test cases. Each test case is described as follows:

  • The first line contains two integers \(n\) and \(m\) separated by a space.
  • The next \(n\) lines each contain \(m\) space-separated integers representing the grid.

It is guaranteed that \(1 \leq n, m \leq 1000\) and the grid values are integers.

outputFormat

For each test case, output a single integer on a new line – the minimum number of operations required to make all elements of that grid zero.

## sample
4
2 2
1 2
3 0
3 3
0 0 0
0 0 0
0 0 0
3 4
1 0 3 0
2 4 0 1
0 3 2 0
3 3
8 6 0
3 5 4
0 1 2
2

0 3 3

</p>