After leaving Los Angeles, Little AD arrived in the InfO(1)Cup Ski Resort, the largest ski resort in the InfO(1)Cup Kingdom. The ski resort is made of points numbered from to . The height of point is , and . There are no two points that have the same height.
For any two points and with , there exists one chairlift that takes skiers from point to point and one slope that takes skiers from point to point . Taking the slope from point to point takes exactly seconds. Please note that when taking the slope from point to point , skiers are not required to visit all points with . Moreover, when taking a chairlift from point to point , skiers cannot stop at any point .
It takes a skier seconds to get on a chairlift at point (regardless of where the chairlift goes) and seconds to get off a chairlift at point (regardless of where that chairlift comes from). .
Little AD wants to make a -second circuit. That is, he wants to start from point , visit all other points exactly once, and then return to point , and he wants to spent at least seconds on the slopes.
Little AD hates (as much as any proven skier) to stay in one point for too long. Therefore, let be the total time Little AD spends at point , and let be the maximum value along all . Note that and, for all :
- , if Little AD reaches point on a slope and leaves point on a slope;
- , if Little AD reaches point with a chairlift and leaves point on a slope;
- , if Little AD reaches point on a slope and leaves point with a chairlift;
- , if Little AD reaches point with a chairlift and leaves point with a chairlift.
Task
Now Little AD wonders: how much time does he need to spend in a single point so that he skis for a total of at least seconds? That is, what is the minimum value of he could achieve in order to spend at least seconds on the slopes?
Little AD needs your help! For given scenarios, you must find the minimum value of and help Little AD enjoy his well deserved ski holiday!
Input data
The first line of input contains , the number of scenarios your program will have to solve. For each of the scenarios, the first line will contain and . The -th following lines will contain three values , , . Please note that the input does not contain the values , and , since .
Output data
There should be exactly lines of output, with the -th line of output containing the answer for the -th scenario.
Constraints and clarifications
- It is guaranteed that Little AD can ski at least seconds;
- ;
- Let denote the sum of the values of for all scenarios.
- ;
- ;
- , for all .
# | Points | Restrictions |
---|---|---|
1 | 6 | |
2 | 9 | |
3 | 19 | |
4 | 22 | |
5 | 44 | No further restrictions. |
Example
stdin
2
3 5
1 8 6
5 3 2
2 6 8
3 6
1 8 6
5 3 2
2 6 8
stdout
2
8
Explanation
First scenario. Little AD gets on the chairlift at point , then he gets off at point and skies down to point . There he skies down to point , where he skies back to point .
Second scenario. Little AD gets on the chairlift at point and goes up to point , where he gets off. Then he skies down to point . There he gets on the chairlift and goes up to point , where he gets down and skies back to point .