N = int(input()) t = 0 for _ in range(N): a, b ,c, d = map(int, input().replace(':', ' ').split()) s = a*60 + b e = c*60 + d t += e - s + [0, 1440][ s > e] print(t)