#include <iostream>
#include <cstring>
using namespace std;
int main()
{
char str1[60],str2[60],str3[60],str4[60];
cin>>str1>>str2>>str3>>str4;
int len1=strlen(str1);
int len2=strlen(str2);
int len3=strlen(str3);
int len4=strlen(str4);
int len5,len6;
if(len1>len2)
{
len5=len2;
}
else
{
len5=len1;
}
if(len3>len4)
{
len6=len4;
}
else
{
len6=len3;
}
char day;
int shi;
int j1;
for(j1=0;j1<len5;j1++)
{
int pp=str1[j1];
if(str1[j1]==str2[j1]&&pp>=65&&pp<=71)
{
day=str1[j1];
break;
}
}
for(int j3=j1+1;j3<len5;j3++)
{
int p1=str1[j3];
int p2=str2[j3];
if((p1==p2)&&((p1>=48&&p1<=57)||(p1>=65&&p1<=78)))
{
shi=p1;
break;
}
}
if(day=='A')
{
cout<<"MON ";
}
else if(day=='B')
{
cout<<"TUE ";
}
else if(day=='C')
{
cout<<"WED ";
}
else if(day=='D')
{
cout<<"THU ";
}
else if(day=='E')
{
cout<<"FRI ";
}
else if(day=='F')
{
cout<<"SAT ";
}
else if(day=='G')
{
cout<<"SUN ";
}
if(shi>=48&&shi<=56)
{
shi=shi-48;
cout<<"0"<<shi<<":";
}
else if(shi>=65&&shi<=78)
{
shi=shi-55;
cout<<shi<<":";
}
int fen;
for(int j2=0;j2<len6;j2++)
{
int p=str3[j2];
if(str3[j2]==str4[j2]&&((p<=90&&p>=65)||(p>=97&&p<=122)))
{
fen=j2;
break;
}
}
if(fen<10)
{
cout<<"0"<<fen;
}
else
{
cout<<fen;
}
return 0;
}