#include<bits/stdc++.h>
using namespace std;
#define int long long
struct student{
int gender;
int grade;
int time;
int flag;
int last;
int times;
int able;
int tot;
string level;
};
struct record{
string date,id;
int h1,m1,s1;
int h2,m2,s2;
double len;
int m,s;
int step;
}b[150005];
int cmp(record a,record b){
if(a.h1 != b.h1) return a.h1 < b.h1;
if(a.m1 != b.m1) return a.m1 < b.m1;
return a.s1 < b.s2;
}
unordered_map<string,student> a;
unordered_map<string,int> pret;
unordered_map<string,string> pred;
string name[10005];
int n,m;
int second(int m,int s){
return m * 60 + s;
}
int LongRun(int time,int gender){
if(gender == 1){
if(time <= second(12,30)) return 20;
if(time <= second(13,0)) return 18;
if(time <= second(13,30)) return 16;
if(time <= second(14,0)) return 14;
if(time <= second(14,30)) return 12;
if(time <= second(15,10)) return 10;
if(time <= second(15,50)) return 8;
if(time <= second(16,30)) return 6;
if(time <= second(17,10)) return 4;
if(time <= second(18,0)) return 2;
return 0;
}else{
if(time <= second(6,40)) return 20;
if(time <= second(6,57)) return 18;
if(time <= second(7,14)) return 16;
if(time <= second(7,31)) return 14;
if(time <= second(7,50)) return 12;
if(time <= second(8,05)) return 10;
if(time <= second(8,20)) return 8;
if(time <= second(8,35)) return 6;
if(time <= second(8,50)) return 4;
if(time <= second(9,0)) return 2;
return 0;
}
}
int Check_SunnyRun(int num,string date,string lastd,string id,int time,double len,int pause,int step,int gender,int last,int now){
if(gender == 0 && len * 1000.0 < 1500.0) return 0;
if(gender == 1 && len * 1000.0 < 3000.0) return 0;
double avr_speed = (len * 1000.0 / time);
if(avr_speed < 2.0 || avr_speed > 5.0) return 0;
if(pause > second(4,30)) return 0;
double avr_step = len * 1000.0 / step;
if(avr_step > 1.5) return 0;
int date1=0,date2=0;
for(int i=0;i<date.size();i++){
date1 *= 10;
date1 += date[i] - '0';
}
for(int i=0;i<lastd.size();i++){
date2 *= 10;
date2 += lastd[i] - '0';
}
if(date2 - date1 > 1) return 1;
if(date1 == date2 && now - last < 21600) return 0;
if(date1 != date2 && 86400 - last + now < 21600) return 0;
return 1;
}
int SunnyRun(int times){
if(times >= 21) return 10;
if(times >= 19) return 9;
if(times >= 17) return 8;
if(times >= 14) return 7;
if(times >= 11) return 6;
if(times >= 7) return 4;
if(times >= 3) return 2;
return 0;
}
int BodyExam(string id){
if(a[id].flag) return 10;
return 0;
}
int FinalTest(string id){
return a[id].last;
}
int Attendance(int able,int times){
int cnt = able + times;
if(cnt >= 18) return 5;
if(cnt >= 15) return 4;
if(cnt >= 12) return 3;
if(cnt >= 9) return 2;
if(cnt >= 6) return 1;
return 0;
}
string SetLevel(int tot){
if(tot >= 95) return "A";
if(tot >= 90) return "A-";
if(tot >= 85) return "B+";
if(tot >= 80) return "B";
if(tot >= 77) return "B-";
if(tot >= 73) return "C+";
if(tot >= 70) return "C";
if(tot >= 67) return "C-";
if(tot >= 63) return "D+";
if(tot >= 60) return "D";
return "F";
}
void Getin(){
cin >> n;
for(int i=1;i<=n;i++){
string id;
char gender;
char passed;
int m,s;
char tmp;
cin >> id;
cin >> gender;
cin >> a[id].grade;
cin >> m >> tmp >> s >> tmp;
cin >> passed;
cin >> a[id].last >> a[id].times;
if(gender == 'M') a[id].gender = 1;
else a[id].gender = 0;
if(passed == 'P') a[id].flag = 1;
else a[id].flag = 0;
a[id].time = second(m,s);
name[i] = id;
}
sort(name+1,name+1+n);
cin >> m;
for(int i=1;i<=m;i++){
string date,id;
int h1,m1,s1;
int h2,m2,s2;
double len;
int m,s;
int step;
char tmp;
cin >> date >> id;
cin >> h1 >> tmp >> m1 >> tmp >> s1;
cin >> h2 >> tmp >> m2 >> tmp >> s2;
cin >> len;
cin >> m >> tmp >> s >> tmp;
cin >> step;
int gender = a[id].gender;
int lastt;
string lastd;
if(!pret.count(id)) lastt = -1e5;
else lastt = pret[id];
if(!pred.count(id)) lastd = "0";
else lastd = pred[id];
int stay = second(m,s);
int time = 0;
if(m2 >= m1){
if(s2 >= s1) time += second(m2-m1,s2-s1);
else time += second(m2-1-m1,s2+60-s1);
}else{
h2 --;
if(s2 >= s1) time += second(m2+60-m1,s2-s1);
else time += second(m2+60-1-m1,s2+60-s1);
}
time += (h2 - h1) * 3600;
int add = Check_SunnyRun(i,date,lastd,id,time,len,second(m,s),step,a[id].gender,lastt,h1*3600+second(m1,s1));
if(add != 0){
pret[id] = h2*3600+second(m2,s2);
pred[id] = date;
}
a[id].able += add;
}
}
void Output(){
for(int i=1;i<=n;i++){
string id = name[i];
cout << id << " " << a[id].tot << " " << a[id].level << endl;
}
}
void Calculation(string id){
int grades = 0;
grades += a[id].grade;
grades += LongRun(a[id].time,a[id].gender);
grades += SunnyRun(a[id].able);
grades += FinalTest(id);
grades += BodyExam(id);
grades += Attendance(a[id].able,a[id].times);
a[id].tot = grades;
a[id].level = SetLevel(a[id].tot);
}
void Student(){
for(int i=1;i<=n;i++){
string id = name[i];
Calculation(id);
}
}
void Run(){
Getin();
Student();
Output();
}
signed main(){
Run();
return 0;
}