n,h,m,t = map(int,input().split()) mod_h,mod_m = 24,60 cnt_h,cnt_m = divmod(t*(n-1),mod_m) print((h+cnt_h)%mod_h) print((m+cnt_m)%mod_m)