#P7784. King of Hot Pot
King of Hot Pot
King of Hot Pot
Problem Description
Little Q is enjoying hot pot together with Tangjz. There are dishes of meat in the boiling water, labeled by . The -th dish of meat will be OK to eat at time , and it will take Little Q units of time to swallow it. It is impossible for Little Q to swallow more than one dish of meat at the same moment. Note that for the -th dish of meat, Little Q can choose to ignore it for a while and swallow it later. Little Q is called "King of Hot Pot", and he wants to show off before Tangjz by swallowing dishes of meat as soon as possible. Please write a program to help Little Q find dishes of meat and the order to swallow them such that the time he spends on reaching the target is minimized for every possible value of (). Note that the time for waiting is also included in the answer.
Input
The first line of the input contains a single integer (), the number of test cases. For each case, the first line of the input contains an integer (), denoting the number of dishes of meat. Each of the following lines contains two integers and (), denoting each dish of meat. It is guaranteed that the sum of all is at most .
Output
For each test case, output a single line containing integers, the -th () of which denoting the minimum possible units of time needed for Little Q to swallow dishes of meat.
Sample Input
1
5
1 2
4 6
3 5
4 2
3 2
Sample Output
3 5 7 12 18
Source
2020 Multi-University Training Contest 2