#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string.h>
using namespace std;
const int maxn=;
char s1[maxn],s2[maxn],s3[maxn],s4[maxn];
int a,b,c;
char week[][]={"MON","TUE","WED","THU","FRI","SAT","SUN"};
int main()
{
scanf("%s %s %s %s",s1,s2,s3,s4);
int len1=strlen(s1);
int len2=strlen(s2);
int l12=min(len1,len2);
int len3=strlen(s3);
int len4=strlen(s4);
int l34=min(len3,len4);
int idx=;
for(int i=;i<l12;i++){
if(s1[i]==s2[i] && s1[i]>='A' && s1[i]<='G'){
a=s1[i]-'A';
idx=i;
break;
}
}
for(int i=idx+;i<l12;i++){
if(s1[i]==s2[i]){
if(s1[i]>='A' && s1[i]<='N'){
b=s1[i]-'A'+;
break;
}
else if(s1[i]>='' && s1[i]<=''){
b=s1[i]-'';
break;
}
}
}
for(int i=;i<l34;i++){
if(s3[i]==s4[i] && ((s3[i]>='A'&&s3[i]<='Z')||(s3[i]>='a'&&s3[i]<='z'))){
c=i;
break;
}
}
printf("%s %02d:%02d",week[a],b,c);
return ;
}