N = int(input()) t = 0 for _ in range(N): hs, ms ,he, me = map(int, input().replace(':', ' ').split()) t += ((he*60+me) - (hs*60+ms) + 1440) % 1440 print(t)