package hello;
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
String word;
Scanner in = new Scanner(System.in);
int hour=0;
int minute=0;
int second=0;
while(true) {
word = in.next();
if(word.equals("END")) {
System.out.print(hour + ":" + minute + ":" + second);
break;
}
if(word.indexOf('$') == 0 && word.indexOf('*') > 0) {
int loc1 = word.indexOf(',');
int loc2 = word.indexOf(',', loc1+ 1);
if(word.charAt(loc2+1) == 'A') {
int check_num = 0;
int loc3 = word.indexOf('*');
for(int i = 1;i < loc3;++i) {
check_num ^= (int)word.charAt(i);
}
check_num %= 65536;
int correct = Integer.parseInt(word.substring(loc3+1), 16);
if(check_num == correct) {
int time = (int)Double.parseDouble(word.substring(loc1+1,loc2));
hour = time / 10000;
minute = time % 10000 / 100;
second = time % 100;
hour = (hour + 8) % 24;
}
}
}
}
}
}