# -*- coding: utf-8 -*- N, H, M, T = map(int, input().split()) minutes = (N-1)*T minutes %= (24*60) hours = minutes // 60 minutes %= 60 M += minutes H += hours + (M // 60) M %= 60 H %= 24 print(H) print(M)