#!/usr/bin/env python3 #fileencoding: utf-8 N, H, M, T = [int(i) for i in input().strip().split(" ")] M += (N-1) * T H += M // 60 print(H%24) print(M%60)