# coding: utf-8 import math n, h, m, t = map(int,input().split()) m1 = t * (n-1) h1 = (m1//60)%24 m1 %= 60 #print(h1,m1) h = (h + h1) % 24 m += m1 if m >= 60: h = (h+1) % 24 m = m % 60 print(h) print(m)