Server Time: Sat Feb 22, 2020 9:20 am
Welcome ( logout
E - Lighting System Design
PDF (English) Ranklist
Time Limit: 2 second(s) Memory Limit: 32 MB

You are given the task to design a lighting system for a huge conference hall. After doing a lot of calculation & sketching, you have figured out the requirements for an energy-efficient design that can properly illuminate the entire hall. According to your design, you need lamps of n different power ratings. For some strange current regulation method, all the lamps need to be fed with the same amount of current. So, each category of lamp has a corresponding voltage rating. Now, you know the number of lamps and cost of every single unit of lamp for each category. But the problem is that you are to buy equivalent voltage sources for all the lamp categories. You can buy a single voltage source for each category (each source is capable of supplying to infinite number of lamps of its voltage rating) and complete the design. But the accounts section of your company soon figures out that they might be able to reduce the total system cost by eliminating some of the voltage sources and replacing the lamps of that category with higher rating lamps. Certainly you can never replace a lamp by a lower rating lamp as some portion of the hall might not be illuminated then. You are more concerned about money-saving rather than energy-saving. Find the minimum possible cost to design the system.

Input

Input starts with an integer T (≤ 100), denoting the number of test cases.

Each case starts with a line containing an integer n (1 ≤ n ≤ 1000). Each of the next n lines contains four integers Vi, Ki, Ci and Li (1 ≤ Vi ≤ 105, 1 ≤ Ki ≤ 1000, 1 ≤ Ci ≤ 10, 1 ≤ Li ≤ 100). Here the integers in ith line have the following meaning.

1.      Vi means the voltage rating,

2.      Ki means the cost of a voltage source of this category,

3.      Ci means the cost of a lamp of this category and

4.      Li means the number of required lamps of this category.

You can assume that the voltage rating for the categories will be distinct.

Output

For each case, print the case number and the minimum possible cost to design the system.

Sample Input

Output for Sample Input

1

3

100 500 10 20

120 600 8 16

220 400 7 18

Case 1: 778

 


Problem Setter: Mohammad Mahmudur Rahman
Special Thanks: Jane Alam Jan (Solution, Dataset)
Developed and Maintained by
JANE ALAM JAN
Copyright © 2012
LightOJ, Jane Alam Jan