Micro's Spot

2.8

9 votes
Easy
Problem

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 ith row and A[i][j] is maximum in jth 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] ≤ 109

Time Limit: 1
Memory Limit: 256
Source Limit:
Editor Image

?