#include <iostream> #include <cstdio> #include <algorithm> #include <string.h> using namespace std; const int maxn=100; char s1[maxn],s2[maxn],s3[maxn],s4[maxn]; int a,b,c; char week[7][10]={"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=0; for(int i=0;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+1;i<l12;i++){ if(s1[i]==s2[i]){ if(s1[i]>='A' && s1[i]<='N'){ b=s1[i]-'A'+10; break; } else if(s1[i]>='0' && s1[i]<='9'){ b=s1[i]-'0'; break; } } } for(int i=0;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 0; }