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