N,H,M,T=map(int,input().split(" ")) while(N-1): carrier=T//60 rest=T%60 if(rest+M>=60): carrier+=1 rest-=60 H+=carrier M+=rest if(H>=24): H=H%24 #150 -> 2,30 #1:40 -> 3:40+30 -> 3:70 N-=1 print(str(H)) print(str(M))