Hive

No attempts yetTime limit1sMemory limit256 MB

Problem

A field of pink flowers is divided into NN rows and MM columns of one square meter cells. The cell in row ii from the top and column jj from the left holds aija_{ij} flowers.

Every morning a group of rabbits comes to eat the flowers so that their fur turns pink. A rabbit starts at the top left cell and travels to the bottom right cell, moving one cell right or one cell down at a time. It never goes back to the left and never goes back up. Whenever a rabbit enters a cell that still holds at least one flower, it picks exactly one flower there. It walks past a cell with no flowers left without picking anything.

You may choose the route of every rabbit. Find the smallest number of rabbits needed to pick every flower in the field.

Input

The first line contains the number of test cases TT (1T101 \le T \le 10).

The first line of each test case contains the number of rows and columns of the field, NN and MM (1<N,M16001 < N, M \le 1600).

Each of the next NN lines contains MM integers. The jj-th integer on the ii-th line is aija_{ij} (0aij1000 \le a_{ij} \le 100).

Output

For each test case, print the smallest number of rabbits needed to pick every flower, one answer per line.