micros-spot

Micro loves watching Big Bang Theory and his favorite character is Sheldon. Just like Sheldon he also wants his spot, so he divided his room into an N*M matrix. He then assigned two numbers to each cell. A[i][j] denotes first number he assigned to cell (i,j) and B[i][j] denotes second number he assigned to cell (i,j). Micro loves a cell (i,j), and calls it Micro's Spot, if value of B[i][j] is maximum in i^th row and A[i][j] is maximum in j^th column. Help find total number of Micro's Spot.

Input:
First line consists of an integer T denoting number of test cases.
First line of each test case consists of two space separated integers denoting N and M. Then 2N lines follow each containing M space separated integers. First N lines denote matrix A and following N lines denote matrix B.

Output:
Print the answer to each test case in a new line.

Constraints:
1 ≤ T ≤ 10
1 ≤ N, M ≤ 1000 
0 ≤ A[i][j], B[i][j] ≤ 10^9

SAMPLE INPUT
1
2 2
2 0
0 1
1 0
0 2

SAMPLE OUTPUT
2

Source: hackerearth | Difficulty: EASY


Solutions: