n,h,m,t=map(int, input().split()) m += t * (n-1) h = (h + m//60) % 24 m %= 60 print(h, m, sep="\n")