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