import java.util.*; class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int n = in.nextInt(); int sum = 0; for(int i = 0; i < n; i++) { String sleeptime = in.next(); String waketime = in.next(); int k_1 = sleeptime.indexOf(":"); int k_2 = waketime.indexOf(":"); int h_sleep = Integer.valueOf(sleeptime.substring(0, k_1)); int m_sleep = Integer.valueOf(sleeptime.substring(k_1+1, sleeptime.length())); int h_wake = Integer.valueOf(waketime.substring(0, k_2)); int m_wake = Integer.valueOf(waketime.substring(k_2+1, waketime.length())); sum += h_wake * 60; sum += m_wake; if(h_wake - h_sleep < 0) { sum += (24 - h_sleep - 1) * 60; sum += 60 - m_sleep; } else { sum -= h_sleep * 60; sum -= m_sleep; } System.out.println(sum); } System.out.println(sum); } }