There will be multiple test cases. Each test case begins with a line containing a single integer N (1 ≤ N ≤ 50), the number of guards available. There will then be N blocks of data, one for each guard.
Each block provides the preferences of one guard. A block begins with two integers, K (1 ≤ K ≤ 50) and M (1 ≤ M ≤ 1440), in that order; K is the number of time intervals specifying when the guard is available for work, and M is the maximum number of minutes s/he is able to work each day. The next K lines each contains the starting and ending time, in that order, of a time interval where the guard is available, separated by whitespace. These time intervals may overlap. The union of all K time intervals provides the complete set of times at which the guard is available.
A starting or ending time is formatted as HH:MM (00 ≤ HH ≤ 23, 00 ≤ MM ≤ 59). Midnight is represented by 00:00. When the ending time is smaller than the starting time, it means the guard is available for working past midnight. For example, the interval “23:00 03:00” means the guard is available from 11pm at night to 3am in the morning. If the starting and ending times are equal, then the guard is available for work during any time intervals throughout the day. The last test case is followed by a line with a single 0.