#include<iostream>
#include<string>
using namespace std;
/*
没难度,仅供大家参考
*/
struct Stu {
string name;
char gender;
string id;
int grade;
}stu[10005];
int N;
int main() {
cin >> N;
int m_cnt=0, f_cnt=0;
int high=-1, low=1000;
int high_index, low_index;
for (int i = 0; i < N; i++) {
cin>>stu[i].name >> stu[i].gender >> stu[i].id >> stu[i].grade;
if (stu[i].gender == 'M') {
m_cnt++;
if (low > stu[i].grade) {
low = stu[i].grade;
low_index = i;
}
}
if (stu[i].gender == 'F') {
f_cnt++;
if (high < stu[i].grade) {
high = stu[i].grade;
high_index = i;
}
}
}
if (f_cnt == 0)printf("Absent\n");
else {
cout << stu[high_index].name << " " << stu[high_index].id<<endl;
}
if (m_cnt == 0)printf("Absent\n");
else {
cout << stu[low_index].name << " " << stu[low_index].id << endl;
}
if (f_cnt == 0 || m_cnt == 0) {
printf("NA");
}
else printf("%d", abs(high - low));
system("pause");
return 0;
}