import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
public class TestFinal1 {
public static void main(String[] args) throws IOException {
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
int participantQuantity = Integer.parseInt(bufferedReader.readLine());
Participant[] participants = new Participant[participantQuantity];
for (int i = 0; i < participantQuantity; i++) {
StringTokenizer stringTokenizer = new StringTokenizer(bufferedReader.readLine());
String login = stringTokenizer.nextToken();
int solvedProblems = Integer.parseInt(stringTokenizer.nextToken());
int penalty = Integer.parseInt(stringTokenizer.nextToken());
participants[i] = new Participant(login, solvedProblems, penalty);
}
heapSort(participants);
result(participants);
}
public static void heapSort(Participant[] participants) {
List<Participant> heap = new ArrayList<>();
for (Participant participant : participants) {
heapAdd(heap, participant);
}
for (int j = 0; j < participants.length; j++) {
participants[j] = getMaxPriority(heap);
}
}
private static void heapAdd(List<Participant> heap, Participant key) {
heap.add(key);
siftUp(heap, heap.size() - 1);
}
private static Participant getMaxPriority(List<Participant> heap) {
Participant result = heap.get(0);
heap.set(0, heap.get(heap.size() - 1));
heap.remove(heap.size() - 1);
siftDown(heap, 0);
return result;
}
private static void siftDown(List<Participant> heap, int index) {
int left = 2 * index + 1;
int right = left + 1;
if (left >= heap.size()) {
return;
}
int indexLargest;
if (right < heap.size() && compare(heap.get(left), heap.get(right))) {
indexLargest = right;
} else {
indexLargest = left;
}
if (compare(heap.get(index), heap.get(indexLargest))) {
swap(heap, index, indexLargest);
siftDown(heap, indexLargest);
}
}
private static void siftUp(List<Participant> heap, int index) {
if (index == 0) {
return;
}
int parentIndex = (index - 1) / 2;
if (compare(heap.get(parentIndex), heap.get(index))) {
swap(heap, parentIndex, index);
siftUp(heap, parentIndex);
}
}
private static int compare(Participant participant1, Participant participant2) {
if (participant1.getProblems() < participant2.getProblems()) {
return -1;
} else if (participant1.getProblems() > participant2.getProblems()) {
return 1;
}
if (participant1.getPenalty() > participant2.getPenalty()) {
return -1;
} else if (participant1.getPenalty() < participant2.getPenalty()) {
return 1;
}
return participant1.getLogin().compareTo(participant2.getLogin());
}
private static void swap(List<Participant> heap, int index1, int index2) {
Participant tmp = heap.get(index1);
heap.set(index1, heap.get(index2));
heap.set(index2, tmp);
}
private static void result(Participant[] participants) {
StringBuffer stringBuffer = new StringBuffer();
for (Participant participant : participants) {
stringBuffer.append(participant.getLogin()).append("\n");
}
System.out.println(stringBuffer);
}
}
class Participant implements Comparable<Participant> {
private String login;
private int problems;
private int penalty;
public Participant(String login, int solvedProblems, int penalty) {
this.login = login;
this.problems = solvedProblems;
this.penalty = penalty;
}
public String getLogin() {
return login;
}
public int getProblems() {
return problems;
}
public int getPenalty() {
return penalty;
}
@Override
public int compareTo(Participant that) {
int result = Integer.compare(this.getProblems(), that.getProblems());
if (result == 0) {
result = Integer.compare(that.getPenalty(), this.getPenalty());
}
if (result == 0) {
result = this.getLogin().compareTo(that.getLogin());
}
return result;
}
}