#include<iostream>
using namespace std;
int n;
int a[100], b[100], c[100], x[100];
string s[100], temp;
int main() {
cin >> n;
for (int i = 0; i < n; i++)cin >> s[i] >> a[i] >> b[i] >> c[i];
for (int i = 0; i < n; i++) {
for (int j = 1; j < n; j++) {
if (a[i] > a[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
else if (a[i] == a[j]) {
if (b[i] > b[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
else if (b[i] == b[j]) {
if (c[i] > c[j]) {
temp = s[i];
s[i] = s[j];
s[j] = temp;
}
}
}
}
}
for (int i = 0; i < n; i++)cout << s[i] << endl;
}