#include<iostream>
#include<string>
#include<cctype>
using namespace std;
int main() {
#ifdef LOCAL
freopen("d:\\datain.txt", "r", stdin);
//freopen("d:\\dataout.txt", "w", stdout);
#endif LOCAL
string a, b, c, d;
cin >> a >> b >> c >> d;
int i = 0, j = 0;
char t[2];
string week[7] = { "MON","TUE","WED","THU","FRI","SAT","SUN" };
while (i < a.length() && i < b.length()) {
if ((a[i] == b[i]) && (a[i] >= 'A'&&a[i] <= 'G')) {
cout << week[a[i] - 'A'] << " ";
break;
}
i++;
}
i++;
while (i < a.length() && i < b.length()) {
if (a[i] == b[i] && ((a[i] >= 'A'&&a[i] <= 'N') || isdigit(a[i]))) {
//cout << "t:" << a[i] << endl;
int t1 = isdigit(a[i]) ? a[i] - '0' : a[i] - 'A' + 10;
printf("%02d:", t1);
break;
}
i++;
}
while (j < c.length() && j < d.length()) {
if (c[j]==d[j]&&isalpha(c[j])){
printf("%02d", j);
break;
}
j++;
}
}