A team of cavers is standing in the entrance hall of a cave, on the ground, whose altitude above sea level is known.
The cave has halls, numbered to , and the entrance hall is hall . They are joined by corridors, which connect all the halls without ever letting you walk in a circle. For every corridor we know the two halls it joins and the height difference between them.
Your task is to find the lowest altitude the cavers can descend to inside the cave.
Input
First line of input will be a single integer - the number of testcases.
First line of each testcase contains two integers and - the altitude of the ground in the entrance hall, and the number of halls.
In the next lines will be three integers , and describing one corridor: the hall it starts from, the hall it leads to, and the height difference between them. Every corridor is written pointing away from the entrance, so is always the hall closer to the entrance. A negative means the hall it leads to is lower than the one it starts from.
Output
For every testcase print a single line with the lowest altitude the cavers can reach.
Example
1 278 7 1 2 -20 1 3 -10 2 4 -5 2 5 10 3 6 -33 3 7 7
235
The deepest point is hall . Getting there means walking from hall down to hall , which costs metres, and then down again to hall for another : .
Constraints
the corridors reach every hall, and there is no way to walk in a circle
the sum of over all testcases does not exceed
This problem was adapted, with permission, from Pećine, authored by Društvo matematičara Srbije and Fondacija Petlja.