Cats have nine lives, but you have 114514 lives.
Description
You have $n$ tasks to complete, where the $i$-th task takes $t_i$ days. However, human life is limited, and you only have $c$ days left.
Preparation is key; you can spend $1$ day to deeply contemplate the $i$-th task, which will reduce the time required for it by $d_i$ days. Specifically, if the time is reduced to zero or a negative number, the task can be completed instantly. However, human inspiration is limited, and each task can only be deeply contemplated once per lifetime.
You can be resurrected, and each resurrection grants you another $c$ days. The results of previous deep contemplations are preserved and do not disappear upon resurrection.
Find the minimum number of times you need to be resurrected to complete all tasks in your last life. You can assume that you cannot perform any tasks before your last life; you can only contemplate tasks. In your last life, you can both contemplate and perform tasks.
Input
The first line contains a positive integer $T$, representing the number of test cases. The format for each test case is as follows:
- The first line contains two positive integers $n$ and $c$, representing the number of tasks and the length of one life, respectively.
- The next $n$ lines each contain two positive integers $t_i$ and $d_i$, describing a task.
Output
For each test case, output a single non-negative integer representing the minimum number of resurrections required.
Examples
Input 1
2 3 5 17 5 5 2 15 4 2 1345 1344 1 10 10
Output 1
3 0
Note 1
For the first test case:
In the first three lives, contemplate each task once. The time required for the tasks becomes $2, 0, 3$ respectively.
In the last life, contemplate task $1$ and task $3$, then complete all tasks instantly.
A total of four lives are used, requiring three resurrections. It can be proven that no solution exists with fewer than $3$ resurrections.
For the second test case:
First, contemplate the second task, then complete the second task instantly. Then, complete the first task in the following $1344$ days.
Input 2
1 3 1 1000000000 1 1000000000 1 1000000000 1
Output 2
2999999999
Input 3
(See the provided files ex_rebirth*.in/ex_rebirth*.ans, which correspond to subtasks 2 through 5.)
Constraints
This problem uses bundled testing; you must pass all test cases in a subtask to receive points for that subtask.
For all data, $1\le T\le 1000, 1\le \sum n\le 2\times 10^5, 1\le c\le 10^9, 1\le d_i\le t_i\le 10^9$.
| Subtask ID | Special Properties | Score |
|---|---|---|
| $1$ | $\sum n,\sum t_i\le 7$ | $10$ |
| $2$ | $n,t_i\le 30, T\le 100$ | $20$ |
| $3$ | $\sum n\le 3000$ | $20$ |
| $4$ | $c\ge n$ | $20$ |
| $5$ | $30$ |