import sys read=sys.stdin.buffer.read readline=sys.stdin.buffer.readline readlines=sys.stdin.buffer.readlines n, k=map(int, readline().split()) spu=list(map(int, read().split())) s=spu[::3] p=spu[1::3] u=spu[2::3] ans=[] v0=[[] for _ in range(100001)] for i in range(n): v0[u[i]].append(i) v0.sort(key=lambda w: -len(w)) import copy def solve(t): global ans v=copy.deepcopy(v0) for w in v: w.sort(key=lambda i: s[i]*(10**7)-p[i]) while True: if not v[0]: break tops=[] for w in v: if not w: break i=w.pop() if s[i]==t: tops.append(i) tops.sort(key=lambda i: p[i]) ans+=tops for i in range(10, -1, -1): solve(i) print('\n'.join(map(str, ans[:k])))