Fibonacci Bugs

Time limit: 0.2s Memory limit: 64MB Input: Output:

Bug colonies have been the center of attention of scientists for a long time. Through some technological advancements, we are now able to describe a bug colony using a number known as the degree of the colony. A colony of degree 00 represents a male bug and one of degree 11 represents a female bug. A colony of degree i>1i > 1 is obtained by merging a colony of degree i1i - 1 together with a colony of degree i2i - 2. As such, the first few colonies are as follows:

  • Colony 00: a male
  • Colony 11: a female
  • Colony 22: a male and a female
  • Colony 33: a male and two females

You are the owner of the biggest bug farm in the world, having at your disposal a virtually infinite amount of colonies of any degree. Each day you receive NN offers, each described by two numbers AiA_i and BiB_i, meaning that you can sell as many colonies of type AiA_i as you want and get BiB_i money for each colony of that type.

Unfortunately, the antitrust laws on the bug trading market forbid you to sell more than KK bugs in a single day (selling a colony is equivalent to selling all the bugs in that colony).

Task

Given the description of TT days, if you optimally choose which offers to accept, what is the maximum amount of money you can obtain in each day?

Input data

The first line will contain the number of days TT.

The first line of each day contains the number of bugs NN and the most bugs you can sell that day KK. The next NN lines of each day contain the pair of numbers AiA_i and BiB_i.

Output data

You will print TT lines, the ithi^{th} one containing the answer for the ithi^{th} day.

Constraints and clarifications

  • 1T,N,K,Ai1051 \leq T, N, K, A_i \leq 10^5
  • i=1TNi105\sum_{i=1}^{T}N_i \leq 10^5
  • 1Bi1091 \leq B_i \leq 10^9
  • For tests worth 50 points: 1N,K5 5001 \leq N, K \leq 5 \ 500 and 1Ai11 0001 \leq A_i \leq 11 \ 000.

Example

stdin

1
5 11
1 2
2 2
3 5
4 9
5 50

stdout

56

Explanation

It is optimal to choose the 5th5^{th} offer once and the 1st1^{st} one 33 times.

Log in or sign up to be able to send submissions!