N, H, M, T = map(int, input().split()) clock = H * 60 + M + T * (N - 1) hour = clock // 60 minute = clock - hour * 60 print(hour % 24) print(minute)