public static void main(String[] args) throws IOException {
		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
		String line = "";
		StringBuilder out = new StringBuilder();
		PriorityQueue<Register> pq = new PriorityQueue<Register>();
		while ((line = in.readLine()) != null && !line.equals("#")) {
			String[] info = line.split(" ");
			pq.add(new Register(Integer.parseInt(info[2]), Integer
					.parseInt(info[1])));
		}
		int k = Integer.parseInt(in.readLine().trim());
		Register e;
		while (k > 0) {
			e = pq.poll();
			out.append(e.name + "\n");
			pq.add(new Register(e.per, e.name, e.time + e.per));
			k--;
		}
		System.out.print(out);
	}