N, H, M, T = (map(int, input().split())) at = H *60 + M + (N-1)*T C = at//1440 A = (at-C*1440)//60 B = at%60 print(A) print(B)