Under construction

Still being built. Things may change

Candy

Interview

Time limit1sMemory limit256 MB

Summary
Pack J candies using the fewest boxes by filling the largest capacity boxes first.
Level

Easy3 of 10

Topics
Greedy, Sorting
Solved
No attempts yet

Problem

You own a candy factory. Every day you pack JJ candies into boxes and send them to the store.

The factory has NN boxes, and their sizes can differ. You want to use as few boxes as possible. A box does not have to be filled completely, so a partly filled box is fine.

Read the number of candies and the size of every box, then print the smallest number of boxes that holds all of the candies. The boxes are guaranteed to have enough room for all of the candies.

Input

The first line contains the number of test cases TT (1≤T≤101 \le T \le 10). Each test case has the form below.

The first line of a test case contains the number of candies JJ and the number of boxes NN (1≤J,N≤10001 \le J, N \le 1000).

Each of the next NN lines contains the height RiR_i and the width CiC_i of the ii-th box (1≤Ri,Ci≤100001 \le R_i, C_i \le 10000). Two boxes may have the same size. One box holds at most Ri×CiR_i \times C_i candies.

Output

Print TT lines. On each line print the smallest number of boxes needed for the ii-th test case.

Examples4

  1. Example 1

    Input
    1
    20 5
    3 4
    2 5
    1 8
    3 3
    2 5
    
    Expected output
    2
    
  2. Example 2

    Input
    2
    12 3
    2 7
    1 5
    3 2
    20 3
    2 7
    1 5
    3 2
    
    Expected output
    1
    2
    
  3. Example 3

    Input
    1
    1 1
    1 1
    
    Expected output
    1
    
  4. Example 4

    Input
    1
    10 5
    2 2
    2 2
    2 2
    2 2
    2 2
    
    Expected output
    3