P21359 [HackerEarth] 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 numb
普及-
题目描述

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

输入格式

见题面

输出格式

见题面

样例输入
3 5 7 52 61 63 53 28 37 53 44 93 79 90 60 19 13 79 28 62 59 15 81 76 80 94 13 12 61 73 94 30 9 80 89 28 31 61 25 30 23 58 14 23 95 33 53 48 61 31 60 14 85 30 41 24 63 42 70 65 65 60 43 65 19 43 59 8 100 56 99 43 12 10 11 98 82 66 49 87 14 16 73 25 97 20 32 62 30 89 75 83 79 100 25 66 80 1 90 39 41 38 28 40 38 57 66 73 91 74 10 56 72 92 85 52 39 53 40 27 72 42 26 85 37 34 49 86 96 34 58 9 25 14 5 94 75 16 48 67 62 82 92 30 96 71 51 1 91 44 5 74 23 30 45 57 99 16 57 81 64 8 81 93 73 18 24 8 36 67 85 86 13 77 50 24 59 30 91 10 10 93 73 79 41 36 41 92 25 36 42 12 10 36 65 100 19 64 87 48 87 9 100 79 86 38 81 52 77 39 58 25 100 10 80 13 91 96 72 67 40 89 56 14 30 77 89 66 92 78 83 89 14 68 58 46 89 21 77 32 37 96 61 65 40 28 35 100 52 36 52 10 19 39 15 53 79 28 14 47 37 79 42 70 48 6 38 42 97 4 51 66 8 71 36 78 43 46 38 81 24 36 53 21 57 65 84 39 23 16 79 34 52 9 98 10 3 26 89 41 32 89 8 77 55 8 61 14 62 76 6 62 93 47 70 31 88 48 23 46 75 46 42 80 94 89 80 13 55 54 50 97 12 47 99 70 38 46 65 22 73 83 40 78 39 1 11 48 24 77 53 35 11 55 91 91 90
样例输出
38 32 88 0 23