#include<unordered_map>
#include<vector>
#include<iostream>
#include<algorithm>
using namespace std;
struct Student{
int id, best;
int score[4], rank[4];
};
int sortby =-1;
bool cmp (Student a, Student b)
{
return a.score[sortby] > b.score[sortby];
};
int main()
{
int n, m, id;
scanf("%d%d",&n,&m);
vector<Student> stu(n+1);
for (int i = 0; i < n; i++){
scanf("%d%d%d%d",&stu[i].id,&stu[i].score[1],&stu[i].score[2],&stu[i].score[3]);
stu[i].score[0] = (stu[i].score[1] + stu[i].score[2] + stu[i].score[3]) / 3;
}
for (sortby = 0; sortby < 4; sortby++){
sort(stu.begin(),stu.end(),cmp);
stu[0].rank[sortby] = 1;
for (int i = 1; i < n; i++){
if (stu[i].score[sortby] != stu[i-1].score[sortby])
stu[i].rank[sortby] = i+1;
else
stu[i].rank[sortby] = stu[i-1].rank[sortby];
}
}
unordered_map<int, int> index;
for (int i = 0; i < n; i++){
index.insert(pair<int,int>(stu[i].id,i));
stu[i].best = 0;
int minr = stu[i].rank[0];
for (int j = 1; j < 4; j++){
if (stu[i].rank[j] < minr){
stu[i].best = j;
minr = stu[i].rank[j];
}
}
}
char symbol[] = "ACME";
for (int i = 0; i < m; i++){
scanf("%d",&id);
if (index.find(id) == index.end())
printf("N/A\n");
else{
int best = stu[index[id]].best;
printf("%d %c\n",stu[index[id]].rank[best], symbol[best]);
}
}
return 0;
}