#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;

struct student{
    char name[12];    //姓名 
    char id[12];
    int grade;
}temp,M,F;

void inti(){
    M.grade = 101;
    F.grade = -1;
}


int main(){
    inti();

    int n;
    scanf("%d",&n);

    char gender;
    for(int i=0;i<n;i++){
        scanf("%s %c %s %d",temp.name,&gender,temp.id,&temp.grade);

        if(gender == 'M' && temp.grade<M.grade)    M = temp;
        else if(gender == 'F' && temp.grade>F.grade)    F = temp;
    }

    if(F.grade == -1)     printf("Absent\n");
    else printf("%s %s\n",F.name,F.id);

    if(M.grade == 101)     printf("Absent\n"); 
    else printf("%s %s\n",M.name,M.id);    

    if(F.grade==-1 || M.grade == 101)    printf("NA");
    else printf("%d",F.grade-M.grade);


    return 0;
}