#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
const int maxn = 1010;
struct person {
string name;
string num;
int scr;
}m[maxn],w[maxn];
bool cmp2(struct person& a, struct person& b) {
return a.scr < b.scr;
}
bool cmp1(struct person& a, struct person& b) {
return a.scr > b.scr;
}
int main()
{
int n;
cin >> n;
int cnt_m = 0, cnt_w = 0;
for (int i = 0; i < n; i++) {
string str1, str2, str3;
int tmp;
cin >> str1 >> str2 >> str3 >> tmp;
if (str2 == "M") {
m[cnt_m].name = str1;
m[cnt_m].num = str3;
m[cnt_m++].scr = tmp;
}
if (str2 == "F") {
w[cnt_w].name = str1;
w[cnt_w].num = str3;
w[cnt_w++].scr = tmp;
}
}
if (cnt_w != 0) {
sort(w, w + cnt_w, cmp1);
cout << w[0].name << " " << w[0].num << endl;
}
else {
cout << "Absent" << endl;
}
if (cnt_m != 0) {
sort(m, m + cnt_m, cmp2);
cout << m[0].name << " " << m[0].num << endl;
}
else {
cout << "Absent" << endl;
}
if (cnt_m != 0 && cnt_w != 0) {
cout << abs(m[0].scr - w[0].scr);
}
else {
cout << "NA" << endl;
}
return 0;
}