n,h,m,t = input().split() time = int(h)*60 + int(m) + int(t)*(int(n)-1) time %= 1440 print(time//60) print(time%60)