Integral of All Horrors#3825

Integral of All Horrors

1 second
64 megabytes
Medium

In response to the Deep Horizon oil spill, ACME Inc. develops a machine that uses a high-tech particle beam to remotely seal oil leaks. To test the prototype, ACME has built a underwater test bed with independent oil leaks that are named L_1, L_2, \ldots, L_n.

Each leak L_i (1 \le i \le n) is characterized by parameters r_i and t_i. r_i is the initial oil leakage rate in litres per second (). While L_i is being sealed by the particle beam, the leakage rate would linearly decrease, and reach (i.e. become sealed) after t_i seconds of continual operation.

For example, let L_1 be characterized by r_1 = 20 and t_1 = 4. Initially oil spew at a rate of . After second of sealing, the rate reduces to ; after seconds, the rate is ; after , we have ; and after the leak is sealed. Throughout these seconds, the total volume of oil that leak from L_1 is () () 2 = 40 (area of a triangle). Meanwhile, other leaks continue to spew oil, and are unaffected until the particle beam is directed at them.

You are responsible for demonstrating the machine. At t = 0, you activate the beam to seal leaks. The particle beam takes negligible time to target a leak, and is never idle. Therefore every leak is sealed at t = t_1 + t_2 + \ldots + t_n (and then everyone applauds). However, a lot of oil would be leaked during the test. The precise amount depends how you choose to target the particle beam throughout the demonstration.

Given parameters for L_1, L_2, \ldots, L_n, your task is to minimize total volume (in litres) of oil leakage between t = 0 (particle turned on) and t = t_1 + t_2 + \ldots + t_n (all leaks sealed). Note that there are multiple test cases (all independent from one another).

Input

The first input line contains the number of test cases , 1 \le N \le 50.

Each test case begins with a single line containing an integer . Each of the following lines specifies L_i (for 1 \le i \le n) with two integers r_i and t_i, separated by space.

  • is the total number of oil leaks, and satisfies 1 \le n \le 50.

  • r_i is the initial leakage rate (in ) of L_i, and satisfies 1 \le r_i \le 500.

  • t_i is the total beam time (in ) to seal L_i, and satisfies 1 \le t_i \le 500.

Output

For each test case, print the minimum possible total volume oil spilled during the test (in ), to decimal places.

Examples

Example 1

Loading
Loading