#include<bits/stdc++.h>
#define ll long long
using namespace std;
ll sus,n,s,ac,b,get_to,phy_sum,f,c,class_run,m,ans[10005],qu_m,leg=21600,ti;
ll tw_mo[18]={0,31,28,31,30,31,30,31,31,30,31,30,31};
double l,lm,w,stri;
string p,id[10005];
map<string,ll>c_sum,run_sum;
map<string,ll>sc;
map<string,ll>mf;
char gen,phy;
struct zid
{
string name;
ll grade;
string lev;
}ak[10005];
bool cmp(zid a,zid b)
{
return a.name<b.name;
}
ll long_run(ll time,char mn)
{
if(mn=='M')
{
if(time<=750)
return 20;
else if(time<=780)
return 18;
else if(time<=810)
return 16;
else if(time<=840)
return 14;
else if(time<=870)
return 12;
else if(time<=910)
return 10;
else if(time<=950)
return 8;
else if(time<=990)
return 6;
else if(time<=1030)
return 4;
else if(time<=1080)
return 2;
else
return 0;
}
else
{
if(time<=400)
return 20;
else if(time<=417)
return 18;
else if(time<=434)
return 16;
else if(time<=451)
return 14;
else if(time<=470)
return 12;
else if(time<=485)
return 10;
else if(time<=500)
return 8;
else if(time<=515)
return 6;
else if(time<=530)
return 4;
else if(time<=540)
return 2;
else
return 0;
}
}
ll get_camp(ll sum)
{
if(sum>=18)
return 5;
else if(sum>=15)
return 4;
else if(sum>=12)
return 3;
else if(sum>=9)
return 2;
else if(sum>=6)
return 1;
else
return 0;
}
ll get_day()
{
ll a=45,mo,da,s=0;///cout<<a<<"???????????{}{}{}{{}{}\n";
//cout<<"|||";
cin>>a;
a-=20170000;
da=a%100;
mo=(a-da)/100;
for(ll i=1;i<mo;++i)
s+=tw_mo[i];
s+=da;
return s*86400;
}
ll get_begin()
{
ll ht,mt,s;
char s1,s2;
cin>>ht>>s1>>mt>>s2>>s;
//cout<<ht<<"???"<<mt<<"???"<<s<<"\n";
return ht*3600+mt*60+s;
}
ll get_sus()
{
ll a,b;
char ls1,ls2;
cin>>a>>ls1>>b>>ls2;
return a*60+b;
}
string get_lev(ll gr)
{
if(gr>=95)
return "A";
else if(gr>=90)
return "A-";
else if(gr>=85)
return "B+";
else if(gr>=80)
return "B";
else if(gr>=77)
return "B-";
else if(gr>=73)
return "C+";
else if(gr>=70)
return "C";
else if(gr>=67)
return "C-";
else if(gr>=63)
return "D+";
else if(gr>=60)
return "D";
else
return "F";
}
ll get_long(ll sum)
{
if(sum>=21)
return 10;
else if(sum>=19)
return 9;
else if(sum>=17)
return 8;
else if(sum>=14)
return 7;
else if(sum>=11)
return 6;
else if(sum>=7)
return 4;
else if(sum>=3)
return 2;
else
return 0;
}
int main()
{
ios::sync_with_stdio(0);
cin>>n;
char ls1,ls2;
for(ll i=1;i<=n;++i)
{
cin>>p;
cin>>gen;
cin>>s;
//cout<<s<<"???\n";
cin>>ac>>ls1>>b>>ls2;
//cout<<ac<<"???"<<b<<'\n';
get_to=long_run(ac*60+b,gen);
cin>>phy;
if(phy=='P')
phy_sum=10;
else
phy_sum=0;
cin>>f>>c;
ans[i]=f+phy_sum+get_to+s;
c_sum[p]=c;
sc[p]=0;
mf[p]=gen;
id[i]=p;
}
ll mp;
cin>>mp;
ll begin,last;
char xb;
//cout<<mp<<"???\n";
for(ll i=1;i<=mp;++i)
{
//cout<<i<<"??\n";
ti=get_day();
//cout<<ti<<"?????????\n";
cin>>p;
begin=get_begin();
last=get_begin();
cin>>l;
lm=l*1000.00*1.00;
sus=get_sus();
cin>>s;
xb=mf[p];
if(xb=='M')
{
if(l<3.00)
continue;
}
else
{
if(l<1.50)
continue;
}
if(sus>270)
{
continue;
}
w=double(lm/(double(last-begin)*1.00));
if(w>5.00||w<2.00)
continue;
stri=lm/double(s*1.00);
if(stri>1.50)
continue;
if(begin-sc[p]<21600)
continue;
++c_sum[p];sc[p]=last;++run_sum[p];
}
for(ll i=1;i<=n;++i)
{
ans[i]+=get_camp(c_sum[id[i]])+get_long(run_sum[id[i]]);
ak[i].grade=ans[i];
ak[i].name=id[i];
ak[i].lev=get_lev(ans[i]);
}
sort(ak+1,ak+1+n,cmp);
for(ll i=1;i<=n;++i)
cout<<ak[i].name<<" "<<ak[i].grade<<' '<<ak[i].lev<<'\n';
}