#P1621B. Integers Shop
Integers Shop
Description
The integers shop sells segments. The -th of them contains all integers from to and costs coins.
Tomorrow Vasya will go to this shop and will buy some segments there. He will get all integers that appear in at least one of bought segments. The total cost of the purchase is the sum of costs of all segments in it.
After shopping, Vasya will get some more integers as a gift. He will get integer as a gift if and only if all of the following conditions are satisfied:
- Vasya hasn't bought .
- Vasya has bought integer that is less than .
- Vasya has bought integer that is greater than .
Vasya can get integer as a gift only once so he won't have the same integers after receiving a gift.
For example, if Vasya buys segment for coins and segment for coins, he spends coins and receives integers from these segments. He also gets integers and as a gift.
Due to the technical issues only the first segments (that is, segments ) will be available tomorrow in the shop.
Vasya wants to get (to buy or to get as a gift) as many integers as possible. If he can do this in differents ways, he selects the cheapest of them.
For each from to , find how many coins will Vasya spend if only the first segments will be available.
The first line contains a single integer () — the number of test cases.
The first line of each test case contains the single integer () — the number of segments in the shop.
Each of next lines contains three integers , , () — the ends of the -th segments and its cost.
It is guaranteed that the total sum of over all test cases doesn't exceed .
For each test case output integers: the -th () of them should be the number of coins Vasia will spend in the shop if only the first segments will be available.
Input
The first line contains a single integer () — the number of test cases.
The first line of each test case contains the single integer () — the number of segments in the shop.
Each of next lines contains three integers , , () — the ends of the -th segments and its cost.
It is guaranteed that the total sum of over all test cases doesn't exceed .
Output
For each test case output integers: the -th () of them should be the number of coins Vasia will spend in the shop if only the first segments will be available.
Note
In the first test case if then Vasya can buy only the segment for coins and get integers.
The way to get integers for coins in case is described in the statement.
In the second test case note, that there can be the same segments in the shop.