/*
#include<stdio.h>
#include<string.h>
typedef struct answer_
{
char c;
int a;
char m[1001];
} answer;
typedef struct after_
{
char c[1001];
int n;
} after;
int main()
{
int n,i,j,h=0,len,b=1,k=0,m=0;
answer st[101],te;
after t[101],mp;
int arr[6]= {0},alt[101]= {0};
scanf("%d",&n);
//scanf("%c",&st[i].c);
for(i=1; i<=n; i++)
{
scanf(" %c %d %s",&st[i].c,&st[i].a,st[i].m);
for(j=1;j<=i;j++)
{
if(t[j].n==st[i].a)
{
k=j;
}
}
if(st[i].c=='D' && k!=0)
{
t[k].n=0;
h--;
}
else if(st[i].c=='I' && k==0)
{
t[i].n=st[i].a;
len=strlen(st[i].m);
for(j=0;j<len;j++)
{
t[i].c[j]=st[i].m[j];
}
h++;
}
}
for(i=1; i<=5; i++)
{
scanf("%d",&arr[i]);
}
/*
for(i=1;i<h;i++)
{
for(j=1;j<=n-i;j++)
{
if(t[j].n > t[j+1].n)
{
mp=t[j];
t[j]=t[j+1];
t[j+1]=mp;
}
}
}
for(i=1;i<=h;i++)
{
}
/*
for(i=1; i<=n; i++) //this
{
if(st[i].a!=0)
{
h++;
len = strlen(st[i].m);
for(j=0; j<len; j++)
{
t[h].c[j]=st[i].m[j];
}
t[h].n=st[i].a;
}
}
for(i=1; i<=b; i++)
{
printf("%d\n",alt[i]);
}
/*
for(i=1;i<=h;i++)
{
printf("%d %s\n",t[i].n,t[i]);
}
*/
/*
for(i=1;i<=n;i++)
;
{
if(st[i].a!=0 && st[i-1].a==0)
{
for(j=i;j>=1;j--)
1
{
if(st[j-1].a!=0)
{
break;
}
else
{
te=st[j];
st[j]=st[j-1];
st[j-1]=te;
}
}
}
}
*//*
for(i=1;i<=10;i++)
{
for(j=1;j<=5;j++)
{
if(arr[j]==i)
if(m!=0)
{
printf("%d %s\n",t[i].n,t[i].c);
}
}
return 0;
}
*/
#include<stdio.h>
typedef struct answer_
{
int math_number;
char name[1001];
}answer;
int main()
{
answer st[101],input;
int i,n,j,m=0,arr[6]={0};
char put;
scanf("%d",&n);
for(i=0;i<n;i++)
{
scanf(" %c %d %s",&put,&input.math_number,input.name);
m=0;
if(put=='I')
{
if(i==0)
{
st[i]=input;
}
else
{
for(j=0;j<i;j++)
{
if(input.math_number<st[j].math_number)
{
break;
}
else if(st[j].math_number==input.math_number)
{
m++;
break;
}
}
if(m==0){
for(j=n-1;j>=0;j--)
{
st[j-1]=st[j];
}
st[i]=input;}
}
}
else
{
for(j=0;j<i;j++)
{
if(st[j].math_number==input.math_number)
{
m=j;
}
}
if(m!=0)
{
for(j=n-1;j>=m;j--)
{
if(j!=m)
{
st[j]=st[j-1];
}
}
}
}
}
for(i=0;i<5;i++)
{
scanf("%d",&arr[i]);
}
for(i=0;i<5;i++)
{
printf("%d %s\n",st[arr[i]].math_number,st[arr[i]].name);
}
return 0;
}



