#P1932F. Feed Cats
Feed Cats
Description
There is a fun game where you need to feed cats that come and go. The level of the game consists of steps. There are cats; the cat is present in steps from to , inclusive. In each step, you can feed all the cats that are currently present or do nothing.
If you feed the same cat more than once, it will overeat, and you will immediately lose the game. Your goal is to feed as many cats as possible without causing any cat to overeat.
Find the maximum number of cats you can feed.
Formally, you need to select several integer points from the segment from to in such a way that among given segments, none covers two or more of the selected points, and as many segments as possible cover one of the selected points.
The first line of input contains a single integer () — the number of test cases. Then the descriptions of the test cases follow.
The first line of each test case contains two integers and (, ).
The -th of the next lines contains a pair of integers and ().
The sum of for all tests does not exceed , the sum of for all tests does not exceed .
For each test case, print a single integer, the maximum number of cats you can feed.
Input
The first line of input contains a single integer () — the number of test cases. Then the descriptions of the test cases follow.
The first line of each test case contains two integers and (, ).
The -th of the next lines contains a pair of integers and ().
The sum of for all tests does not exceed , the sum of for all tests does not exceed .
Output
For each test case, print a single integer, the maximum number of cats you can feed.
Note
In the first example, one of the ways to feed five cats is to feed at steps and .
- At step , cats , , and will be fed.
- At step , cats and will be fed.