import static java.lang.Integer.parseInt; import java.util.Scanner; class A { static Scanner s = new Scanner(System.in); public static void main(String[] args) { String in[]; int r=0; s.nextLine(); while(s.hasNextLine()) { in = s.nextLine().split("( |:)"); r += (parseInt(in[2])-parseInt(in[0])+24)%24*60 + (parseInt(in[3])-parseInt(in[1])); System.out.println(r); } } }