#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
struct student{
char name[12];
char id[12];
char g;
int grade;
}stu[20010];
int main()
{
int n,k1 = -1,k2 = -1,high = -1,low = 1000;
scanf("%d",&n);
for(int i = 0; i < n; i++)
{
scanf("%s %c %s %d",stu[i].name,&stu[i].g,stu[i].id,&stu[i].grade);
if(stu[i].g == 'F' &&stu[i].grade > high)
{
k1 = i;high = stu[i].grade;
}
else if(stu[i].g == 'M' &&stu[i].grade < low)
{
k2 = i;low = stu[i].grade;
}
}
k1>=0?printf("%s %s\n",stu[k1].name,stu[k1].id):printf("Absent\n");
k2>=0?printf("%s %s\n",stu[k2].name,stu[k2].id):printf("Absent\n");
k1 >=0 && k2 >= 0?printf("%d\n",stu[k1].grade - stu[k2].grade):printf("NA\n");
return 0;
}