#include int main() { int N, H, M, T; scanf("%d%d%d%d", &N, &H, &M, &T); M += T*(N-1); H += M/60; printf("%d\n%d\n", H%24, M%60); return 0; }