#include <iostream>
#include<cstring>
using namespace std;
//注意题目表意不明,一对的意思是同一位置下,同时结束条件是小于两对中较小的那对
bool isLetter1(char c,char c1) {
if (c >= 'A' && c <= 'G'&&c1 >= 'A' && c1 <= 'G')
return true;
else
return false;
}
bool isLetter2(char c, char c1) {
if (c >= 'A' && c <= 'N' && c1 >= 'A' && c1 <= 'N')
return true;
else
return false;
}
bool isNum(char c, char c1) {
if (c >= '0' && c <= '9' && c1 >= '0' && c1 <= '9')
return true;
else
return false;
}
int main() {
char ch[4][61];//60分钟加一个'\0'
int day=0,tag=0,hour=0,minute=0;
string date[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
for (int i = 0; i < 4; i++) {
cin >> ch[i];
}
for (int i = 0; i < strlen(ch[0]) && i < strlen(ch[1]); i++) {
if (tag==0&&ch[0][i] == ch[1][i] && isLetter1(ch[0][i], ch[1][i])) {//注意一些坑:字母的范围
day = ch[0][i] - 'A' + 1;
tag = 1;
continue;
}
if (tag == 1 && ch[0][i] == ch[1][i] && (isLetter2(ch[0][i], ch[1][i])|| isNum(ch[0][i], ch[1][i]))) {
if (isLetter2(ch[0][i], ch[1][i])) {
hour = ch[0][i] - 'A' + 10;
}
if (isNum(ch[0][i], ch[1][i])) {
hour = ch[0][i] - '0';
}
break;
}
}
int num = 0;
for (int i = 0; i < strlen(ch[2]) && i < strlen(ch[3]); i++) {
if (ch[2][i] == ch[3][i]&&! isNum(ch[2][i], ch[3][i])) { //小坑:分钟不能根据数字相同判断,只能根据字母相同
minute = num;
}
num++;
}
cout << date[day-1] << " ";
if (hour < 10) {
cout << "0" << hour << ":";
}
else
cout <<hour << ":";
if (minute < 10) {
cout << "0" << minute;
}
else
cout << minute <<endl;
return 0;
}