Chef is the event manager of his college. He has been assigned the task to manage the upcoming tech fest. There are $K$ rooms where the event can take place, and at a particular time only one event can be organized in a room for a particular time interval.
Each event coordinator has their strictly preferred room $P_i$, and if the room is already occupied he simply cancels that event.Chef wants to maximize the total number of events,and so he allows or disallows certain events in order to achieve the task . Chef is busy handling his events so the chef needs your help .
Given a list of $N$ events with their start time $S_i$,end time $E_i$ and preferred room $P_i$,you need to calculate the maximum number of events that can take place.
Note that the $i$th event wants to occupy the $p_i$ room from [$s_i$, $f_i$) .

-----Input:-----
The first line contains an integer $T$ denoting the number of test cases . Each of the next $T$ lines contains two integers $N$ and $K$ , the number of events and the number of rooms respectively . Each of the next $N$ lines contains three integers $s_i$ ,$e_i$ and $p_i$,the start time ,end time and the preferred room of ith event.

-----Output:-----
Print the maximum number of events that can take place.

-----Constraints-----
- $1 \leq T \leq 100$
- $1 \leq N \leq 10^3$
- $1 \leq  K \leq 10^5$
- $1 \leq  Si <  Ei \leq 10^9$
- $1 \leq Pi \leq K$

-----Sample Input:-----
1

4 2
1 10 1
10 20 2
15 50 2
20 30 2

-----Sample Output:-----
3

-----EXPLANATION:-----
Chef can allow events 1st ,2nd and 4th,to get the maximum 3.

```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\r\n# import math\r\nfrom math import gcd\r\n# import re\r\n# from heapq import *\r\n# from collections import defaultdict as dd\r\n# from collections import OrderedDict as odict\r\n# from collections import Counter as cc\r\n# from collections import deque\r\n# sys.setrecursionlimit(10**5)#thsis is must\r\n# mod = 10**9+7; md = 998244353\r\n# m = 2**32\r\ninput = lambda: sys.stdin.readline().strip()\r\ninp = lambda: list(map(int,sys.stdin.readline().strip().split()))\r\n# def C(n,r,mod):\r\n#   if r>n:\r\n#       return 0\r\n#   num = den = 1\r\n#   for i in range(r):\r\n#       num = (num*(n-i))%mod\r\n#       den = (den*(i+1))%mod\r\n#   return (num*pow(den,mod-2,mod))%mod\r\n# M = 1000000+1\r\n# pfc = [i for i in range(M+1)]\r\n# def pfcs(M):\r\n#     for i in range(2,M+1):\r\n#         if pfc[i]==i:\r\n#             for j in range(i+i,M+1,i):\r\n#                 if pfc[j]==j:\r\n#                     pfc[j] = i\r\n#     return\r\n#______________________________________________________\r\nfor _ in range(int(input())):\r\n    n,k = map(int,input().split())\r\n    d = [[] for i in range(k+1)]\r\n    for i in range(n):\r\n        l,r,p = map(int,input().split())\r\n        d[p].append([l,r])\r\n    ans = 0\r\n    for i in d:\r\n        if len(i)==0:\r\n            continue\r\n        ans+=1\r\n        t = sorted(i,key = lambda x:(x[1],x[0]))\r\n        final = t[0][1]\r\n        for j in range(1,len(t)):\r\n            if t[j][0]>=final:\r\n                ans+=1\r\n                final = t[j][1]\r\n    print(ans)      '
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14019