N, H, M, T = map(int,input().split()) WakeupH = H WakeupM = M DurationM = ((N-1) * T) % 60 DurationH = ((N-1) * T) // 60 WakeupH += DurationH WakeupM += DurationM if WakeupM >= 60: WakeupM = WakeupM % 60 WakeupH += WakeupM // 60 if WakeupH >= 24: WakeupH = WakeupH % 24 print (WakeupH) print (WakeupM)