#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
using namespace std;
bool cmp(tuple<string, int, int, int>a, tuple<string, int, int, int>b) {
if (get<1>(a) == get<1>(b)) { //κ΅μ΄ μ μκ° κ°μλ
if (get<2>(a) == get<2>(b)) { //κ΅μ΄μ μμ μμ΄μ μκ° κ°μλ
if (get<3>(a) == get<3>(b)) { //κ΅μ΄,μμ΄,μν μ μκ° κ°μλ
return get<0>(a) < get<0>(b); //μ¬μ μμΌλ‘ μΆλ ₯
}
return get<3>(a) > get<3>(b); //μνμ μκ° κ°μνλ μμΌλ‘ μΆλ ₯
}
return get<2>(a) < get<2>(b); //μμ΄ μ μκ° μ¦κ°νλ μμΌλ‘ μΆλ ₯
}
else return get<1>(a) > get<1>(b); //κ΅μ΄ μ μκ° λ€λ₯Όλ κ°μνλ μμΌλ‘ μΆλ ₯
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(0);
int N; cin >> N;
vector<tuple<string, int, int, int>>v;
while (N--) {
string name;
int kor, eng, math;
cin >> name >> kor >> eng >> math;
v.push_back(make_tuple(name, kor, eng, math));
}
sort(v.begin(), v.end(), cmp);
for (int i = 0; i < v.size(); i++) {
cout << get<0>(v[i]) << "\n";
}
}
λκΈ