#!/usr/bin/env python3 import collections import heapq def team_key(team): return (-team[0], team[1], team[2], team[3]) def main(): n, k = map(int, input().split()) data = [tuple(map(int, input().split())) for _ in range(n)] univ = collections.defaultdict(list) for i in range(n): u = data[i][2] univ[u].append(i) local_ranks = [-1 for _ in range(n)] for v in univ.values(): v.sort(key=lambda i: (-data[i][0], data[i][1])) for r, i in enumerate(v): local_ranks[i] = r ts = [(data[i][0], local_ranks[i], data[i][1], i) for i in range(n)] if k < n // 3: print(*(t[-1] for t in heapq.nsmallest(k, ts, key=team_key)), sep="\n") else: ts.sort(key=team_key) print(*(t[-1] for t in ts[:k]), sep="\n") if __name__ == '__main__': main()