N=int(input()) total = 0 for i in range(N): H,M,h,m=map(int, input().split()) total += (h-H)*60+(m-M) print(total)