import datetime def GETTIME(H0, M0, H1, M1): DATE0 = datetime.datetime(2023, 6, 5, H0, M0, 0) DATE1 = datetime.datetime(2023, 6, 5, H1, M1, 0) if DATE0 > DATE1: DATE1 = datetime.datetime(2023, 6, 6, H1, M1, 0) DELTA = DATE1 - DATE0 return int(DELTA.total_seconds() / 60) N = int(input()) ANSWER = 0 for _ in range(N): INPUT = input().split() HOURX, MINUTEX = int(INPUT[0].split(':')[0]), int(INPUT[0].split(':')[1]) HOURY, MINUTEY = int(INPUT[1].split(':')[0]), int(INPUT[1].split(':')[1]) ANSWER += GETTIME(HOURX, MINUTEX, HOURY, MINUTEY) print(ANSWER)