public class Main {
static class Elem implements Comparable<Elem>{
public String name;
public int korean, english, math;
@Override
public int compareTo(Elem other) {
//내림차순
if (korean != other.korean) return other.korean - korean;
// 오름차순
if (english != other.english) return english - other.english;
// 내림차순
if (math != other.math) return other.math - math;
// 오름차순
return name.compareTo(other.name);
}
}
public static void main(String[] args) {
Scanner kb = new Scanner(System.in);
int N = kb.nextInt();
Elem[] arr = new Elem[N];
for(int i=0; i<N; i++) {
arr[i] = new Elem();
arr[i].name = kb.next();
arr[i].korean = kb.nextInt();
arr[i].english = kb.nextInt();
arr[i].math = kb.nextInt();
}
Arrays.sort(arr);
StringBuilder sb = new StringBuilder();
for(int i=0; i<N; i++) {
sb.append(arr[i].name).append('\n');
}
System.out.println(sb.toString());
}
}