def main(): n, h, m, t = map(int, input().split(' ')) for i in range(n-1): # print(f'{h}:{m}') res_lst = calc_time(h, m, t) h = res_lst[0] m = res_lst[1] print(h) print(m) def calc_time(h, m, t): time = h*60+m+t # print(time) time = time%1440 # print(time) h = time//60 m = time%60 return [h, m] if __name__ == '__main__': main()