#include<bits/stdc++.h>
using namespace std;
const int N = 1e4+10;
int n,m,s,f,c;//s:体育课专项成绩,f:大一专项计划期末成绩,参加班级训练营的次数
char p;//体质测试过了吗
string times;//长跑时间
string date,from,st,ed,stay,l;
int step;
int h[13]={0,31,28,31,30,31,30,31,31,30,31,30,31};
struct node{
string id;
char xingbie;
int score,c;
string level;
}stu[N];
bool pd(int q1,int q2,int q3,int q4){//判断两个时间大小
if(q1<q3) return true;
if(q1>q3) return false;
if(q2<=q4) return true;
return false;
}
int get_time(string s){//hh:mm:xx
return ((s[1]-'0')+(s[0]-'0')*10)*3600+((s[4]-'0')+(s[3]-'0')*10)*60+((s[7]-'0')+(s[6]-'0')*10);
}
int get_year_time(string s){//2017xxyy
return h[(s[5]-'0'+(s[4]-'0')*10)]*24*60*60+(s[7]-'0'+(s[6]-'0')*10)*24*60*60;
}
int get_double(string s){
int ans=0,sum=0,pos;
for(int i=0;i<s.size();i++){
if(s[i]!='.'){
sum=sum*10+s[i]-'0';
}else{
pos=i+1;
break;
}
}
ans=sum*1000;
sum=0;
for(int i=pos;i<s.size();i++){
sum=sum*10+s[i]-'0';
}
return ans+sum*10;
}
int get_xx_yy(string s){//xx:yy
int sum=0,ans=0,pos;
for(int i=0;i<s.size();i++){
if(s[i]>='0'&&s[i]<='9'){
sum=sum*10+s[i]-'0';
}else{
pos=i+1;
break;
}
}
ans=sum*60;
sum=0;
for(int i=pos;i<s.size()-1;i++){
sum=sum*10+s[i]-'0';
}
return ans+sum;
}
bool cmp(node a,node b){
for(int i=0;i<10;i++){
if(a.id[i]<b.id[i]) return true;
if(a.id[i]>b.id[i]) return false;
}
}
map<string,int>hefa;
map<string,int>is;
map<string,int>pre;
int main(){
cin>>n;
for(int i=1;i<=n;i++){
cin>>stu[i].id>>stu[i].xingbie>>s>>times>>p>>f>>stu[i].c;
pre[stu[i].id]=0;
is[stu[i].id]=i;
if(p=='P') stu[i].score+=10;
stu[i].score+=s+f;
int x=0,y=0,pos;
for(int j=0;j<times.size();j++){
if(times[j]>='0'&×[j]<='9'){
x=x*10+times[j]-'0';
}else{
pos=j+1;
break;
}
}
for(int j=pos;j<times.size()-1;j++){
y=y*10+times[j]-'0';
}
if(stu[i].xingbie=='M'){
if(pd(x,y,12,30)){
stu[i].score+=20;
}else{
if(pd(x,y,13,0)){
stu[i].score+=18;
}else{
if(pd(x,y,13,30)){
stu[i].score+=16;
}else{
if(pd(x,y,14,0)){
stu[i].score+=14;
}else{
if(pd(x,y,14,30)){
stu[i].score+=12;
}else{
if(pd(x,y,15,10)){
stu[i].score+=10;
}else{
if(pd(x,y,15,50)){
stu[i].score+=8;
}else{
if(pd(x,y,16,30)){
stu[i].score+=6;
}else{
if(pd(x,y,17,10)){
stu[i].score+=4;
}else{
if(pd(x,y,18,0)){
stu[i].score+=2;
}
}
}
}
}
}
}
}
}
}
}else{
if(pd(x,y,6,40)){
stu[i].score+=20;
}else{
if(pd(x,y,6,57)){
stu[i].score+=18;
}else{
if(pd(x,y,7,14)){
stu[i].score+=16;
}else{
if(pd(x,y,7,31)){
stu[i].score+=14;
}else{
if(pd(x,y,7,50)){
stu[i].score+=12;
}else{
if(pd(x,y,8,5)){
stu[i].score+=10;
}else{
if(pd(x,y,8,20)){
stu[i].score+=8;
}else{
if(pd(x,y,8,35)){
stu[i].score+=6;
}else{
if(pd(x,y,8,50)){
stu[i].score+=4;
}else{
if(pd(x,y,9,0)){
stu[i].score+=2;
}
}
}
}
}
}
}
}
}
}
}
}//还有阳光长跑合法次数与分数和大一专项计划分数
cin>>m;
for(int i=1;i<=m;i++){
cin>>date>>from>>st>>ed>>l>>stay>>step;
int ll=get_double(l);//精度问题
if((stu[is[from]].xingbie=='M'&&ll>=3000)||(stu[is[from]].xingbie=='F'&&ll>=1500)){
int tmp=get_time(ed)-get_time(st);
if(ll>=2*tmp&&ll<=5*tmp){
if(get_xx_yy(stay)<=270){
if(2*ll<=3*step){
if(get_year_time(date)+get_time(st)-pre[from]>=6*60*60){
hefa[from]++;
pre[from]=get_year_time(date)+get_time(ed);
}
}
}
}
}
}
for(int i=1;i<=n;i++){
int kjm=hefa[stu[i].id];
if(kjm>=21){
stu[i].score+=10;
}else{
if(kjm>=19){
stu[i].score+=9;
}else{
if(kjm>=17){
stu[i].score+=8;
}else{
if(kjm>=14){
stu[i].score+=7;
}else{
if(kjm>=11){
stu[i].score+=6;
}else{
if(kjm>=7){
stu[i].score+=4;
}else{
if(kjm>=3){
stu[i].score+=2;
}
}
}
}
}
}
}
}
for(int i=1;i<=n;i++){
int num=hefa[stu[i].id]+stu[i].c;
if(num>=18){
stu[i].score+=5;
}else{
if(num>=15){
stu[i].score+=4;
}else{
if(num>=12){
stu[i].score+=3;
}else{
if(num>=9){
stu[i].score+=2;
}else{
if(num>=6){
stu[i].score+=1;
}
}
}
}
}
}
for(int i=1;i<=n;i++){
int ohhh=stu[i].score;
if(ohhh>=95){
stu[i].level="A";
}else{
if(ohhh>=90){
stu[i].level="A-";
}else{
if(ohhh>=85){
stu[i].level="B+";
}else{
if(ohhh>=80){
stu[i].level="B";
}else{
if(ohhh>=77){
stu[i].level="B-";
}else{
if(ohhh>=73){
stu[i].level="C+";
}else{
if(ohhh>=70){
stu[i].level="C";
}else{
if(ohhh>=63){
stu[i].level="D+";
}else{
if(ohhh>=60){
stu[i].level="D";
}else{
stu[i].level="F";
}
}
}
}
}
}
}
}
}
}
sort(stu+1,stu+n+1,cmp);
for(int i=1;i<=n;i++){
cout<<stu[i].id<<" "<<stu[i].score<<" "<<stu[i].level<<endl;
}
return 0;
}
/*
2
2015010146 M 45 13'34" P 5 5
2015010000 M 35 13'15" P 2 3
86
20170318 2015010146 18:32:15 18:44:15 2.81 0'0" 3900
20170407 2015010146 18:32:18 18:47:53 2.71 0'0" 3308
20170421 2015010146 22:16:35 22:37:58 2.82 0'0" 2498
20170501 2015010146 07:23:02 07:54:57 3.06 0'0" 3294
20170501 2015010146 08:54:03 09:29:01 4.10 6'31" 539
20170501 2015010146 10:46:17 11:20:56 3.33 0'0" 2970
20170501 2015010146 15:58:15 16:07:36 2.19 0'0" 2486
20170502 2015010146 12:27:03 12:45:01 2.37 0'0" 2176
20170504 2015010146 07:09:10 07:19:54 2.96 0'0" 3329
20170504 2015010146 17:22:14 17:33:24 2.15 0'0" 2104
20170505 2015010146 07:30:00 07:46:53 4.36 0'0" 5813
20170505 2015010146 13:07:02 13:33:19 3.79 0'0" 5330
20170505 2015010146 15:09:17 15:24:41 4.44 0'0" 4307
20170507 2015010146 16:15:55 17:02:29 2.79 0'0" 4434
20170509 2015010146 21:47:33 22:01:35 3.20 0'0" 2831
20170511 2015010146 07:49:30 08:03:28 2.43 0'0" 3683
20170511 2015010146 09:46:20 10:21:21 2.00 4'39" 175
20170513 2015010146 08:59:39 09:12:41 3.60 0'0" 5217
20170513 2015010146 19:38:58 19:46:21 2.13 0'0" 1969
20170514 2015010146 10:37:03 10:55:33 5.00 0'0" 5877
20170514 2015010146 22:03:47 22:33:23 4.97 0'0" 3383
20170515 2015010146 10:24:17 10:39:49 2.71 0'0" 3606
20170515 2015010146 12:03:17 12:19:29 2.04 0'0" 2917
20170515 2015010146 19:52:53 20:21:47 4.34 0'0" 6775
20170517 2015010146 07:22:43 08:11:44 4.98 9'30" 646
20170517 2015010146 14:18:38 14:46:17 3.98 0'0" 4525
20170518 2015010146 10:24:13 10:43:05 2.49 0'0" 3236
20170519 2015010146 11:47:48 11:59:30 3.58 0'0" 3772
20170520 2015010146 07:11:14 08:07:19 4.04 0'0" 3638
20170520 2015010146 10:42:34 10:55:38 3.61 0'0" 3221
20170521 2015010146 14:42:24 15:16:57 2.07 0'0" 2961
20170521 2015010146 19:09:24 19:40:40 3.94 0'0" 3203
20170521 2015010146 21:30:01 21:42:47 3.52 0'0" 4462
20170523 2015010146 14:42:28 14:50:10 2.26 0'0" 2358
20170525 2015010146 11:03:56 11:22:09 2.95 0'0" 4218
20170526 2015010146 13:37:05 13:46:41 2.48 0'0" 3306
20170526 2015010146 22:36:32 22:52:40 4.46 0'0" 3807
20170528 2015010146 14:36:22 14:48:10 3.26 0'0" 5344
20170529 2015010146 15:48:48 15:56:32 2.14 0'0" 2180
20170529 2015010146 18:50:55 19:07:22 4.54 0'0" 4244
20170529 2015010146 21:43:28 21:55:34 3.49 0'0" 5538
20170601 2015010146 07:55:33 08:11:54 4.71 0'0" 4025
20170607 2015010146 15:02:34 15:22:30 3.47 0'0" 4690
20170627 2015010146 18:20:08 18:44:24 3.79 0'0" 4302
20170630 2015010146 15:08:32 15:25:50 4.88 0'0" 5425
20170320 2015010000 11:38:07 12:16:52 3.95 0'0" 3764
20170403 2015010000 22:34:30 22:53:20 4.75 0'0" 4436
20170404 2015010000 07:22:54 08:08:42 2.75 0'0" 2694
20170416 2015010000 13:15:48 13:25:17 2.79 0'0" 3576
20170418 2015010000 08:58:46 09:09:07 2.61 0'0" 2350
20170501 2015010000 08:39:54 09:01:19 4.89 0'0" 7185
20170501 2015010000 11:29:27 11:44:43 3.12 0'0" 3462
20170501 2015010000 16:31:24 16:49:06 3.29 0'0" 4452
20170502 2015010000 08:55:39 09:11:30 2.76 0'0" 2652
20170502 2015010000 13:48:04 14:10:23 4.02 0'0" 3404
20170502 2015010000 17:20:44 17:59:08 2.30 0'0" 2588
20170504 2015010000 16:28:41 16:41:45 3.29 0'0" 4221
20170507 2015010000 14:50:41 15:18:21 3.49 0'0" 5281
20170507 2015010000 17:20:45 17:37:52 3.80 0'0" 4871
20170508 2015010000 21:01:20 21:14:00 4.26 0'0" 4177
20170508 2015010000 21:56:23 22:10:34 3.23 0'0" 3139
20170509 2015010000 10:24:34 10:33:01 2.39 0'0" 2594
20170509 2015010000 17:24:54 17:37:34 2.96 0'0" 2905
20170512 2015010000 12:05:37 12:34:16 2.06 0'0" 2578
20170512 2015010000 14:15:33 14:59:31 3.96 0'0" 5996
20170512 2015010000 14:27:43 14:36:34 2.44 0'0" 4071
20170514 2015010000 19:13:50 19:27:24 3.34 0'0" 5217
20170516 2015010000 16:15:07 16:31:17 3.59 0'0" 3206
20170516 2015010000 20:30:03 21:01:35 4.92 0'0" 4205
20170517 2015010000 20:29:23 21:14:40 3.65 7'19" 211
20170518 2015010000 13:57:06 14:35:06 2.96 0'0" 4061
20170518 2015010000 21:55:34 22:07:57 2.38 0'0" 2378
20170519 2015010000 09:48:55 10:47:47 4.95 0'0" 8108
20170521 2015010000 16:15:53 16:59:09 4.93 0'0" 4567
20170521 2015010000 19:18:14 20:27:58 4.18 0'0" 4648
20170522 2015010000 07:15:36 07:50:21 3.96 0'0" 4773
20170522 2015010000 18:43:11 19:28:12 4.59 0'0" 3993
20170524 2015010000 11:44:20 12:21:50 3.60 0'0" 4800
20170525 2015010000 11:36:58 12:42:56 4.75 0'0" 3392
20170526 2015010000 09:46:31 10:08:21 4.85 0'0" 6550
20170527 2015010000 14:31:38 14:58:30 3.39 0'0" 4907
20170528 2015010000 08:25:58 08:44:09 2.73 0'0" 2784
20170529 2015010000 17:44:08 18:10:13 2.19 0'0" 3370
20170530 2015010000 22:59:40 23:15:18 2.82 0'0" 3352
20170602 2015010000 22:21:20 22:56:16 2.94 0'0" 3715
20170608 2015010000 14:42:13 15:36:42 4.90 0'0" 4761
答案out:
2015010000 72 C
2015010146 87 B+
我的out:
2015010000 69 D+
2015010146 85 B+
*/