#include <iostream>
#include <string>
#include <map>
using namespace std;
int main() {
int n;
if (!(cin >> n)) return 0;
map<string, int> earnings;
for (int i = 0; i < n; ++i) {
int time, boxes;
char complexity;
string name;
cin >> time >> boxes >> complexity >> name;
int rate = 0;
if (complexity == 'L') rate = 3;
else if (complexity == 'N') rate = 4;
else if (complexity == 'H') rate = 5;
int pay = time * 2 + boxes * rate;
earnings[name] += pay;
}
string best_employee;
int max_earnings = -1;
for (const auto& pair : earnings) {
if (pair.second > max_earnings) {
max_earnings = pair.second;
best_employee = pair.first;
}
}
cout << best_employee << endl;
return 0;
}