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 check(rat,rank_mont):\n c=0\n for i in range(len(rank_mont)):\n  if(rat[i]!=rank_mont[i]):\n   c+=1\n return c\n\ndef ranking(rat,rank_min,mont,n,m):\n rat_sort=[]\n \n for i in range(m):\n  rat_sort.append(sorted(rat[i],reverse=True,key=lambda x : x[0]))\n\n for i in range(m):\n  r,j=1,0\n  while(j<n):\n   key=rat_sort[i][j][0]\n   c=0\n   while(j<n):\n    if(key==rat_sort[i][j][0]):\n     if(rank_min[rat_sort[i][j][1]-1]>r):\n      rank_min[rat_sort[i][j][1]-1]=r\n      mont[rat_sort[i][j][1]-1]=i+1\n     c+=1\n    else:\n     break\n    j+=1\n   r+=c\n   \nfor T in range(int(input())):\n n,m=list(map(int,input().split()))\n initial_rating=list(map(int,input().split()))\n rat=[list(map(int,input().split())) for i in range(n)]\n\n rat_player,m_rat_player=[],[]\n for i in range(n):\n  m_rat,x=0,[]\n  for j in range(m):\n   x.append(initial_rating[i]+rat[i][j])\n   initial_rating[i]=x[j]\n   if(m_rat<x[j]):\n    m_rat=x[j]\n    month=j+1\n  rat_player.append(x)\n  m_rat_player.append(month)\n\n rat_month=[]\n for i in range(m):\n  x=[]\n  for j in range(n):\n   x.append([rat_player[j][i],j+1])\n  rat_month.append(x)\n\n rank_min,mont=[501]*(n),[0]*(n)\n\n ranking(rat_month,rank_min,mont,n,m)\n \n count=check(m_rat_player,mont)\n\n print(count)\n \n   \n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 13957