def main(): n, h, m, t = map(int, input().split()) m += h * 60 + t * (n - 1) print(m // 60 % 24) print(m % 60) if __name__ == '__main__': main()