N = int(input()) t = 0 for _ in range(N): H, M, h, m = [int(i) for i in input().replace(":"," ").split(" ")] if H > h or (H == h and M > m): t += (23 - H) * 60 + (60 - M) + ((h * 60) + m) else: t += ((h * 60) + m) - ((H * 60) + M) print(t)