Chef organised a chess tournament, which spanned over $M$ months. There were $N$ players, and player $i$ was rated $R_i$ before the start of the tournament. To see the progress of the players, he noted their rating changes at the end of each month.
After the tournament, FIDE asked Chef to find the number of players whose peak rating and peak ranking did not occur in the same month. In other words, Chef was asked to find the ratings and ranking of each player after each of the $M$ months. Then, using this data, he should find the number of players, such that the month in which they achieved their highest rating over all the months, was different from the month in which they achieved their best rank (based on ratings), over all the months. Note that we do not consider the initial rating/ranking, but only the rating and rankings after each of the $M$ months. 
For a particular player, if there are multiple peak rating or peak ranking months, Chef was to consider the earliest of them. If multiple players had the same rating at the end of some month, they were to be given the same rank. For example, if there were $5$ players, and their ratings at the end of some month were $(2600$, $2590$, $2600$, $2600$ and $2590)$, players $1$, $3$ and $4$ were to be given the first rank, while players $2$ and $5$ should be given the fourth rank.
As Chef hates statistics, he asks you, his friend, to help him find this. Can you help Chef?

-----Input:-----
- The first line contains an integer $T$, the number of test cases.
- The first line of each test case contains two space-separated integers $N$ and $M$, the number of players and the number of months that the tournament spanned over.
- The second line of each test case contains $N$ space-separated integers, $R_1, R_2, \ldots, R_N$ denoting the initial ratings of the players, i.e., their ratings before the start of the tournament.
- The next $N$ lines each contain $M$ space-separated integers. The $j^{th}$ integer of the $i^{th}$ line, $C_{i,j}$ denotes the rating change of the $i^{th}$ player after the $j^{th}$ month.

-----Output:-----
For each test case, print the number of players whose peak ratings did not occur in the same month as their peak ranking, in a new line.

-----Constraints-----
- $1 \le T \le 10$
- $1 \le N,M \le 500$
- $1800 \le R_i \le 2800$
- $-20 \le C_{i,j} \le 20$

-----Subtasks-----
- 30 points : $1 \leq N,M \leq 50$
- 70 points : Original constraints.

-----Sample Input:-----
2
3 3
2500 2500 2520
10 -5 -20
10 15 20
-15 17 13
2 3
2125 2098
-20 10 -10
10 10 -20

-----Sample Output:-----
2
2

-----Explanation:-----
Test case 1:
- 
The ratings for player $1$ after each month are: $(2510$, $2505$ and $2485)$, while his rankings are first, third and third, respectively. Thus, his best rating and best ranking occur after the same month, i.e., after the first month.
- 
The ratings for player $2$ after each month are: $(2510$, $2525$ and $2545)$, while his rankings are first, first and first, respectively. His best rating occurs after the third month, while his best ranking occurs after the first month (we consider the first month even though his peak ranking is over all the months, because we consider only the earliest month where he attains the peak ranking).
- 
The ratings for player $3$ after each month are: $(2505$, $2522$ and $2535)$, while his rankings are third, second and second, respectively. His best rating occurs after the third month, while his best ranking occurs after the second month.
So there are two players ($2$ and $3$), whose peak ratings did not occur in the same month as their peak ranking, and hence the answer is 2.
Test case 2:
- 
The ratings for player $1$ after each month are: $(2105$, $2115$ and $2105)$, while his rankings are second, second and first, respectively. Best rating is after second month, but best ranking is after third month.
- 
The ratings for player $2$ after each month are: $(2108$, $2118$ and $2098)$, while his rankings are first, first and second, respectively. Best rating is after second month, but best ranking is after first month.
So there are two players ($1$ and $2$), whose peak ratings did not occur in the same month as their peak ranking, and hence the answer is 2.

```python

USER_FILENAME = "<user_code>"
import sys, json, builtins
import math, heapq, bisect, itertools, functools, collections, statistics, fractions, decimal, operator, array, random, re, string, os, pathlib
try:
    import resource as _res
except Exception:
    _res = None
from collections import Counter, defaultdict, deque, OrderedDict
from functools import lru_cache, reduce
from itertools import accumulate, permutations, combinations, product
from math import gcd, ceil, floor, sqrt
from decimal import Decimal
try:
    from typing import *
except Exception:
    pass
try:
    sys.setrecursionlimit(1_000_000)
except Exception:
    pass
try:
    import site as _site
    try:
        _sys_sites = _site.getsitepackages() if hasattr(_site, "getsitepackages") else []
        for _p in _sys_sites:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
    try:
        _usp = _site.getusersitepackages()
        if isinstance(_usp, str):
            _usp = [_usp]
        for _p in _usp:
            if _p and _p not in sys.path:
                sys.path.append(_p)
    except Exception:
        pass
except Exception:
    pass

ns = {"__name__": "__main__"}
for _k, _v in list(globals().items()):
    if not _k.startswith("_"):
        ns[_k] = _v
_CODE = 'def getRanking(ratingList,n,m):\n rank = []\n array2d = [[None for i in range(n)] for j in range(m)]\n # print(array2d)\n for i in range(m): #months\n  helper2d = [[None for i in range(2)] for j in range(n)]\n  # print(helper2d)\n  for j in range(n):\n   helper2d[j][0] = j+1\n   helper2d[j][1] = ratingList[j][i]\n  # helper2d = zip(*helper2d)\n  helper2d = sorted(helper2d,reverse=True,key=lambda x:x[1])\n  arr = [x for x in range(1,n+1)]\n  for k in range(1,n):\n   if helper2d[k][1] == helper2d[k-1][1]:\n    arr[k] = arr[k-1]\n  # print(helper2d)\n  for l in range(n):\n   # print("l and i",l,i)\n   array2d[i][helper2d[l][0]-1] = arr[l]\n for l in range(n):\n  minimum = float(\'inf\')\n  minimumIndex = None\n  for o in range(m):\n   if minimum > array2d[o][l]:\n    minimum = array2d[o][l]\n    minimumIndex = o+1\n\n  rank.append(minimumIndex)\n\n  # helper2d = zip(*helper2d)\n # print(array2d)\n # print(arr)\n # print(rank)\n\n return rank\n\n\n\nt = int(input())\nfor _ in range(t):\n n,m = list(map(int,input().split()))\n r = list(map(int,input().split()))\n c = [ None for j in range(n)]\n for i in range(n):\n  c[i] = list(map(int,input().split()))\n ratingList = [None for i in range(n)]\n # print(ratingList)\n for i in range(n):\n  temp = []\n  temp.append(r[i]+c[i][0])\n  for j in range(1,m):\n   temp.append(temp[j-1]+c[i][j])\n  ratingList[i] = temp\n playerRatings = []\n for i in range(n):\n  maximum = float(\'-inf\')\n  maximumMonth = None\n  for j in range(m):\n   if ratingList[i][j] > maximum:\n    maximum = ratingList[i][j]\n    maximumMonth = j+1\n  playerRatings.append(maximumMonth)\n playerRanking = getRanking(ratingList,n,m)\n count = 0\n for i in range(n):\n  if playerRanking[i] != playerRatings[i]:\n   count += 1\n print(count)\n # print(playerRatings)\n # print(playerRanking)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13955