
#include
#include
#include
using namespace std;
int N;
class Student {
public :
string name;
int Korean, English, Math;
bool operator<(const Student& T) const {
if (Korean > T.Korean) return true;
if (Korean < T.Korean) return false;
if (English < T.English) return true;
if (English > T.English) return false;
if (Math > T.Math) return true;
if (Math < T.Math) return false;
if (name < T.name) return true;
else return false;
}
};
Student n[100001];
int main() {
cin >> N;
for (int i = 0; i < N; i++) {
cin >> n[i].name >> n[i].Korean >> n[i].English >> n[i].Math;
}
sort(n, n + N);
for (int i = 0; i < N; i++) {
cout << n[i].name << "\n";
}
}