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