#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
struct Car{
char id[10];
char time[10];
char state[5];
}car[10010],valid[10010];
struct Record{
char id[10];
int length=0;
}record[10010];
bool cmp1(Car a,Car b){
if(strcmp(a.id,b.id)!=0) return strcmp(a.id,b.id)<0;
else return strcmp(a.time,b.time)<0;
}
bool cmp2(Car a,Car b){
return strcmp(a.time,b.time)<0;
}
int calTime(char a[10],char b[10]){
int h1,h2,m1,m2,s1,s2;
int s=0;
h1=(a[0]-'0')*10+a[1]-'0',h2=(b[0]-'0')*10+b[1]-'0';
m1=(a[3]-'0')*10+a[4]-'0',m2=(b[3]-'0')*10+b[4]-'0';
s1=(a[6]-'0')*10+a[7]-'0',s2=(b[6]-'0')*10+b[7]-'0';
s=(h2-h1)*3600+(m2-m1)*60+(s2-s1);
return s;
}
int main()
{
int n,k;
scanf("%d%d",&n,&k);
for(int i=0;i<n;i++){
scanf("%s %s %s",car[i].id,car[i].time,car[i].state);
}
sort(car,car+n,cmp1);
int num=0;
for(int i=0;i<n-1;i++){
if(strcmp(car[i].id,car[i+1].id)==0 && strcmp(car[i].state,"in")==0 && strcmp(car[i+1].state,"out")==0){
valid[num++]=car[i++];
valid[num++]=car[i];
}
}
int count=0;
strcpy(record[0].id,valid[0].id);
for(int i=0;i<num;i++){
if(strcmp(record[count].id,valid[i].id)!=0){
count++;
strcpy(record[count].id,valid[i].id);
}
record[count].length+=calTime(valid[i].time,valid[i+1].time);
i++;
}
int now=0,temp=0;
sort(valid,valid+num,cmp2);
for(int i=0;i<k;i++){
char s[10];
scanf("%s",s);
while(now<num && strcmp(valid[now].time,s)<=0){
if(strcmp(valid[now].state,"in")==0) temp++;
else temp--;
now++;
}
printf("%d\n",temp);
}
int H=record[0].length;
int A[10010];
int index=1;
A[0]=0;
for(int i=1;i<=count;i++){
if(record[i].length>H){
H=record[i].length;
index=1;
A[0]=i;
}else if(record[i].length==H){
A[index++]=i;
}
}
for(int i=0;i<index;i++){
printf("%s ",record[A[i]].id);
}
int maxn=record[A[0]].length;
int hh,mm,ss;
hh=maxn/(3600);
maxn%=3600;
mm=maxn/60;
maxn%=60;
ss=maxn;
printf("%.02d:%.02d:%.02d\n",hh,mm,ss);
return 0;
}