Alice has homework tasks, but she's already bored just thinking about them. To make it more exciting, she decides to set her own deadlines and rewards! She has seconds in total to complete the tasks.
For each , task takes seconds to complete, and Alice has assigned a deadline of seconds to it. She rewards herself with points if she finishes the task before the deadline (including finishing it in the same second as the deadline), or point if she finishes it after the deadline, but still within seconds.
Task
Alice can only work on one homework at a time. Help her maximize her self-awarded score!
Input data
The first line of the input contains a single integer , the number of test cases. test cases follow, each preceded by an empty line.
Each test case consists of:
- a line containing integers , .
- lines, the -th of which consisting of integers , .
Output data
The output must contain lines corresponding to the test cases, each consisting of integer , the maximum number of points Alice can reward herself with.
Constraints and clarifications
- for each
- The sum of across all test cases does not exceed .
# | Points | Constraints |
---|---|---|
1 | 0 | Examples |
2 | 7 | for each |
3 | 12 | for each |
4 | 16 | The sum of across all test cases does not exceed . |
5 | 22 | The sum of across all test cases does not exceed . |
6 | 43 | No additional constraints |
Example
stdin
3
3 2
1 1
1 1
1 1
6 7
1 1
2 2
3 7
2 2
2 2
3 7
4 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
1000000000 1000000000
stdout
3
6
2
Explanation
In the first sample case, Alice has tasks and seconds to work on them. She can complete task in the first second, which is within its deadline, so she gets points for it. Then, she can do task in the second second, so she finishes it after its deadline, but still within her total available time of seconds, so she gets point for it. She does not have time to do more tasks. Her total score is points, and this is the maximum number of points achievable.
In the second sample case, Alice can complete tasks , , and , all within their deadlines, and she can get points for that. It can be seen that she cannot get more than points with any other scheduling of the tasks.