# -*- coding: utf-8 -*- import sys N, H, M, T = tuple(map(int, input().split())) N -= 1 aa = (M + N*T) print((H + int(aa/60))%24) print((M + N*T)%60)