import sys read = sys.stdin.buffer.read readline = sys.stdin.buffer.readline readlines = sys.stdin.buffer.readlines N,H,M,T = map(int,read().split()) x = 60 * H + M + T * (N-1) x %= 1440 h,m = divmod(x,60) print(h,m,sep='\n')