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 = "import sys\nfrom collections import defaultdict\nt=int(input())\n\nfor _ in range(t):\n n,m=list(map(int,input().split()))\n a=list(map(int,input().split()))\n adj=[]\n for _ in range(n):\n  x=list(map(int,input().split()))\n  adj.append(x)\n\n rating=defaultdict(lambda:-1)\n\n\n rank=[[-1 for i in range(m+1)]for j in range(n)]\n\n\n b=[[-1 for i in range(m+1)]for j in range(n)]\n for i in range(n):\n  b[i][0]=a[i]\n for i in range(0,n):\n  for j in range(1,m+1):\n   b[i][j]=b[i][j-1]+adj[i][j-1]\n\n for j in range(1,m+1):\n  g=[]\n  d={}\n  for i in range(n):\n   g.append(b[i][j])\n  z=sorted(g,reverse=True) \n  c=0\n  for i in z:\n   if(i not in d):\n    c+=1\n    d[i]=c\n   else:\n    c+=1\n  for i in range(n):\n   rank[i][j]=d[b[i][j]]\n\n for i in range(n):\n  mx=-1\n  for x in range(1,m+1):\n   mx=max(mx,b[i][x])\n  for j in range(1,m+1):\n   if(b[i][j]==mx):\n    rating[i]=j\n    break\n #print(rating)\n #for i in b:\n  #print(*i)\n c=0\n '''for i in b:\n     print(*i)\n    print()\n    for i in rank:\n     print(*i)'''\n \n for i in range(n):\n  ans=[]\n  mi=sys.maxsize\n  for x in range(1,m+1):\n   mi=min(mi,rank[i][x])\n  for j in range(1,m+1):\n   if(rank[i][j]==mi):\n    if(j!=rating[i]):\n     c+=1\n    break\n\n print(c)\n\n\n"
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14831