#include <stdio.h>
#include <string.h>
struct student {
char name[11];
char sex;
char id[11];
int grade;
}tmp, lowest
, highest;
int main(){
int N, i;
scanf("%d", &N);
lowest.grade = 100;
highest.grade = 0;
for(i = 0; i < N; i++){
scanf("%s %c %s %d", tmp.name, &tmp.sex, tmp.id, &tmp.grade);
if(tmp.sex == 'F'){
if(tmp.grade > highest.grade)
highest = tmp;
} else if(tmp.sex == 'M'){
if(tmp.grade < lowest.grade)
lowest = tmp;
}
}
if(!strlen(highest.name))
printf("Absent\n");
else
printf("%s %s\n", highest.name, highest.id);
if(!strlen(lowest.name))
printf("Absent\n");
else
printf("%s %s\n", lowest.name, lowest.id);
if(strlen(highest.name) && strlen(lowest.name))
printf("%d", highest.grade - lowest.grade);
else
printf("NA");
return 0;
}