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