N, H, M, T = map(int,input().split()) WakeupH = H WakeupM = M WakeupM += (N-1) * T while WakeupM > 60: WakeupH += 1 WakeupM -= 60 print (WakeupH) print (WakeupM)