#Lutece1225. Game Rooms

Game Rooms

Migrated from Lutece 1225 Game Rooms

All parts of this problem, including description, images, samples, data and checker, might be broken. If you find bugs in this problem, please contact the admins.

Description

Your company has just constructed a new skyscraper, but you just noticed a terrible problem: there is only space to put one game room on each floor! The game rooms have not been furnished yet, so you can still decide which ones should be for table tennis and which ones should be for pool. There must be at least one game room of each type in the building.

Luckily, you know who will work where in this building (everyone has picked out offices). You know that there will be TiT_i table tennis players and PiP_i pool players on each floor. Our goal is to minimize the sum of distances for each employee to their nearest game room. The distance is the difference in floor numbers: 00 if an employee is on the same floor as a game room of their desired type, 11 if the nearest game room of the desired type is exactly one floor above or below the employee, and so on.

Input

The first line of the input gives the number of test cases, TT(1T1001\leq T\leq 100). TT test cases follow. Each test case begins with one line with an integer NN(2N40002\leq N\leq 4000), the number of floors in the building. NN lines follow, each consists of 22 integers, TiT_i and PiP_i(1Ti,Pi1091\leq T_i, P_i\leq 10^9), the number of table tennis and pool players on the ii - th floor. The lines are given in increasing order of floor number, starting with floor 11 and going upward.

Output

For each test case, output one line containing Case #x: y, where xx is the test case number (starting from 11) and yy is the minimal sum of distances.

Samples

1
2
10 5
4 3
Case #1: 9

Note

In the first case, you can build a table tennis game room on the first floor and a pool game room on the second floor. In this case, the 55 pool players on the first floor will need to go one floor up, and the 44 table tennis players on the second floor will need to go one floor down. So the total distance is 99.

Resources

The 2015 China Collegiate Programming Contest