#include<bits/stdc++.h>
using namespace std;
struct nide{
string shool;
string team;
int solved;
int time;
}a[200010];
bool cmp(nide x,nide y)
{
if(x.solved!=y.solved) return x.solved>y.solved;
else if(x.solved!=y.solved) return x.time<y.time;
}
int main()
{
int n;
cin>>n;
int sum=0;
for(int i=1;i<=n;i++)
{
cin>>a[i].shool>>a[i].team>>a[i].solved>>a[i].time;
if(a[i].team[a[i].team.size()-1]!='*'&&a[i].solved>=1) sum++;
}
cout<<sum<<endl;
int j=sum*(10/100);
int y=sum*(30/100)-j;
int t=sum*(60/100)-y-j;
string s2;
cin>>s2;
sort(a+1,a+1+n,cmp);
if(s2=="gold")
{
cout<<j<<endl;
for(int i=1;i<=j;i++)
{
cout<<a[i].shool<<a[i].team<<a[i].solved<<a[i].time<<endl;
}
}
else if(s2=="silver")
{
cout<<y<<endl;
for(int i=j+1;i<=j+1+y;i++)
{
cout<<a[i].shool<<a[i].team<<a[i].solved<<a[i].time<<endl;
}
}
else if(s2=="bronze")
{
cout<<t<<endl;
for(int i=y+1;i<=y+1+t;i++)
{
cout<<a[i].shool<<a[i].team<<a[i].solved<<a[i].time<<endl;
}
}
return 0;
}