n = int(input()) hour=0 time=0 for i in range(n): data = input().split() bed = list(map(int,data[0].split(":"))) wake = list(map(int,data[1].split(":"))) if wake[0]>=bed[0]: hour = wake[0] - bed[0] else: hour = 24-bed[0] + wake[0] if wake[1]>=bed[1]: min = wake[1]-bed[1] else: min = 60-bed[1] + wake[1] hour -= 1 if hour<0: hour += 24 time += hour*60 + min print(hour,min) print(time)