n, h, m, t = map(int, input().split()) M = 60*h + m + t*(n-1) print('{}\n{}\n'.format((int(M/60))%24,M%60))