#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <stdlib.h>
#include <vector>
using namespace std;
struct student{
char name[12];
char gender;
char id[12];
int score;
}stu[1010];
bool cmp(student a,student b){
if (a.gender != b.gender) {
return a.gender < b.gender;
}else
return a.score > b.score;
}
int main(){
// printf("hello\n");
int n;
int num_male = 0;
int num_female = 0;
scanf("%d",&n);
for (int i=0; i<n; i++) {
scanf("%s %c %s %d",stu[i].name,&stu[i].gender,stu[i].id,&stu[i].score);
if (stu[i].gender == 'M') {
num_male++;
}else
num_female++;
}
sort(stu, stu+n, cmp);
if (num_female == 0) {
printf("Absent\n");
printf("%s %s\n",stu[n-1].name,stu[n-1].id);
printf("NA");
}
else if (num_male == 0) {
printf("%s %s\n",stu[0].name,stu[0].id);
printf("Absent\n");
printf("NA");
}
else{
printf("%s %s\n%s %s\n",stu[0].name,stu[0].id,stu[n-1].name,stu[n-1].id);
printf("%d",stu[0].score-stu[n-1].score);
}
}