n, h, m, t = list(map(int, input().split())) M = m + (n-1)*t H = h + M//60 M = M % 60 H = H % 24 print(H) print(M)