Mortal Combat

Interview

Time limit2sMemory limit512 MB

Summary
Send heroes one at a time to kill the boss, choosing the order that loses the fewest heroes, or report -1 if the boss wins.
Level

Medium6 of 10

Topics
Greedy, Math, Sorting, Implementation
Solved
No attempts yet

Problem

Vasya has started playing a new video game. At the end of the first level he fights the level boss. He needs to win this fight to keep playing. Vasya has a squad of n heroes, and the i-th hero has hi hit points and ai attack points. The boss has H hit points and A attack points.

The fight goes as follows.

  • If Vasya has no heroes left, he loses the game.

  • If he still has at least one hero, he can pick any one of them and send it to fight the boss.

  • If Vasya picked the i-th hero, the fight goes as follows:

    • The hero attacks the boss and reduces the boss's hit points by ai.
    • If the boss is still alive, that is, has strictly positive hit points, it attacks the hero and reduces the hero's hit points by A.
    • While both the hero and the boss are still alive, the attacks repeat.
  • If the boss is dead, the fight ends and Vasya wins. Otherwise all of the above repeats.

Vasya does not want to lose many heroes on the very first level of the game. So he wants to plan the fight to lose the minimum possible number of heroes. Help him find the minimum number of heroes he can lose while still defeating the boss. If Vasya cannot defeat the boss even by losing all of his heroes, output -1.

Let us look at the samples.

In the first sample the optimal plan is as follows: send hero 2 into the fight first. It attacks the boss three times, reducing its hit points by 12, and then dies. After that Vasya must send hero 3, which immediately reduces the boss's hit points by 6, and the boss dies. So Vasya loses only one hero.

In the second sample Vasya cannot kill the boss no matter in which order he sends his heroes.

Input

The input contains multiple test cases. The first line contains one integer t, the number of test cases (1 ≤ t ≤ 1000).

Each test case is described as follows. The first line contains three integers n, H, A: the number of heroes Vasya has, the boss's hit points, and the boss's attack points (1 ≤ n ≤ 105, 1 ≤ H, A ≤ 109).

Each of the following n lines contains two integers hi, ai: the hit points and attack points of the i-th hero (1 ≤ hi, ai ≤ 109).

The sum of n over all test cases in one input does not exceed 105.

Output

For each test case, output the minimum number of heroes Vasya must lose to defeat the boss, or -1 if he cannot defeat the boss.

Examples1

  1. Example 1

    Input
    2
    4 18 4
    4 5
    9 4
    1 6
    3 3
    4 27 4
    4 5
    9 4
    1 6
    3 3
    
    Expected output
    1
    -1