#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
struct stu {
string name, id;
char s; int grade;
};
int N; vector<struct stu>info;
bool compare(struct stu s1, struct stu s2) {
if (s1.s != s2.s) return s1.s<s2.s;
else return s1.grade > s2.grade;
}
int main() {
cin >> N;
if (N == 0) {
cout << "Absent" << endl << "Absent" << endl << "NA";
return 0;
}
info.resize(N);
for (int i = 0; i < N; i++) {
cin >> info[i].name >> info[i].s >> info[i].id >> info[i].grade;
}
sort(info.begin(), info.end(), compare);
int flag[2] = { 0 };
if (info[0].s == 'F') flag[0] = 1;
if (info[N - 1].s == 'M') flag[1] = 1;
for (int i = 0; i < 2; i++) {
if (flag[i] == 0)
cout << "Absent" << endl;
else {
int index = (i == 0) ? 0 : N - 1;
cout << info[index].name << " " << info[index].id << endl;
}
}
if (flag[0] == 1 && flag[1] == 1) {
cout << info[0].grade - info[N - 1].grade;
}
else cout << "NA";
return 0;
}