Handing Out Books
InterviewTime limit2sMemory limit256 MB
Assign each applicant at most one distinct book numbered within their requested interval to maximize the number of satisfied applicants.
Problem
Jiho is tidying up his room and decided to give away the textbooks he no longer needs. There are books to hand out, and he labeled them with the distinct numbers through so he can tell them apart.
undergraduates at Sogang University applied for a book. Jiho asked each of them to write two integers and () on an application form. He then picks one book that is still left and whose number is between and , and gives it to that student. If books through have all gone to other students already, that student receives nothing.
Jiho can process the applications in any order and can pick any allowed book each time. Find the largest number of students who receive a book.
Input
The first line contains the number of test cases .
The first line of each test case contains the integers () and (), separated by a space. Each of the next lines contains the two integers and () written on one application form.
Output
For each test case, print the largest number of students who receive a book, one per line.