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 = '# cook your dish here\n# cook your dish here\ndef cal(a):\n    \n    a.sort(key=lambda x:x[1])\n    len1=len(a)\n    c=1\n    curr=a[0][1]\n    for p in range(0,len1-1):\n        if curr<=a[p+1][0]:\n            c+=1\n            curr=a[p+1][1]\n    return c\n    \n    \n    \nt=int(input())\nfor i in range(t):\n    n,k=list(map(int,input().split()))\n    list1=[]\n    a=[]\n    count=0\n    for j in range(n):\n        s,f,p=list(map(int,input().split()))\n        list1.append((s,f,p))\n    list1.sort(key=lambda x:x[2])\n    for j in range(0,n-1):\n        if list1[j][2]==list1[j+1][2] and j!=n-2:\n            a.append((list1[j][0],list1[j][1]))\n        elif list1[j][2]==list1[j+1][2] and j==n-2:\n            a.append((list1[j][0],list1[j][1]))\n            a.append((list1[j+1][0],list1[j+1][1]))\n            \n            count+=cal(a)\n            a=[]\n        elif list1[j][2]!=list1[j+1][2] and j==n-2:\n            a.append((list1[j][0],list1[j][1]))\n            count+=cal(a)\n            a=[]\n            a.append((list1[j+1][0],list1[j+1][1]))\n            count+=cal(a)\n            a=[]\n        else:\n            a.append((list1[j][0],list1[j][1]))\n            count+=cal(a)\n            a=[]\n    print(count)\n'
_co = compile(_CODE, USER_FILENAME, "exec")
exec(_co, ns, ns)

```

Measured memory_bytes: 14349