from collections import defaultdict import sys input = sys.stdin.buffer.readline sys.setrecursionlimit(10 ** 7) U = 10**5 def main(): N, K = map(int, input().split()) solve = [[] for _ in range(11)] for i in range(N): S, P, U = map(int, input().split()) solve[S].append((U, P, i)) selected = [0] * (U + 1) for team in solve[::-1]: if not team: continue memo = defaultdict(list) for u, p, i in team: memo[selected[u]].append((p, i)) selected[u] += 1 keys = sorted(memo.keys()) for key in keys: val = sorted(memo[key]) for _, i in val: print(i) K -= 1 if not K: return return main()