n, h, m, t = map(int, input().split()) T = h*60+m+t*(n-1) T %= 24*60 H, M = divmod(T, 60) print(H) print(M)