Golf Courses

No attempts yetTime limit1sMemory limit128 MB

Problem

We want to build golf courses near the New Light apartment complex. Several candidate sites have been surveyed, and for each candidate we know its capacity (the number of clients it can serve) and its construction cost.

Many residents of New Light want to play golf. We must choose some of the candidate sites, build golf courses on them, and assign every client to one of the built courses so that all clients are served, while making the total cost as small as possible.

The total cost has two parts:

  • the total connection cost of the clients to the courses they use, plus
  • the total construction cost of the courses that are built.

Consider the example below.

The links between the candidate sites and New Light form a star graph: New Light is the center vertex, and every other vertex is a candidate site. The number next to New Light is the number of clients who want to play golf. The two numbers next to a candidate site are its construction cost and its capacity. The number on an edge is the distance between New Light and that candidate site; a client who uses that course pays this distance as a connection cost.

For this example, the optimal solution is shown below. Two courses are built, with construction costs 66 and 22. Two clients use the course whose connection cost (distance) is 11, and the remaining three clients use the course whose connection cost is 22. The total construction cost is 6+2=86 + 2 = 8, and the total connection cost is 1+1+2+2+2=81 + 1 + 2 + 2 + 2 = 8, so the total cost is 8+8=168 + 8 = 16.

In the examples, the first test case corresponds to the figures above.

Input

The input is read from standard input and consists of TT test cases. The first line contains the number of test cases TT (1T201 \le T \le 20).

Each test case has the following form. The first line contains a positive integer NN (1N5001 \le N \le 500), the number of candidate sites. The second line contains a positive integer PP (1P100001 \le P \le 10000), the number of clients. Each of the next NN lines describes one candidate site with three positive integers separated by single spaces: the distance from New Light to the site, the construction cost of the course, and the capacity of the course. Every integer is between 11 and 1000010000, inclusive.

The total capacity of the candidate sites is at least PP, so all clients can always be served.

Output

Write to standard output. For each test case, print on its own line the minimum possible total cost, that is, the smallest achievable sum of the total connection cost and the total construction cost.