Enrollment keeps shrinking, so a kindergarten decided to build an oversized binary mobile to attract new students. The mobile is made of wooden rods, beads, and the strings that connect them.
The principal has to clear a spot for the finished mobile and does not know how far it spreads sideways. Given how the rods and beads are connected, the length of each rod, and the weight of each bead, compute the width of the finished mobile. The width is the largest X coordinate the mobile reaches minus the smallest.
The first line has the number of test cases T.
The first line of each test case has the number of rods n (1≤n≤100,000). The i-th of the next n lines has the length of rod i, len (1≤len≤1,000), then two integers l and r describing what hangs from the left end and from the right end, separated by spaces.
If −n≤l≤−1, rod −l hangs from the left end. If 1≤l≤100,000, a bead of weight l hangs from the left end. Read r the same way, except that it describes the right end.
All rods belong to one connected structure rooted at rod 1, and each of rods 2 through n hangs from exactly one rod end.
For each test case print the width of the mobile on its own line. Round to six digits after the decimal point and pad with zeros, so a width of exactly 5 prints as 5.000000.
A rod stays horizontal when the torque on both sides of its hanging point is equal. Write Wl for the weight hanging on the left side of a rod of length len, and Wr for the weight on the right side. The hanging point sits Wl+Wrlen×Wr from the left end and Wl+Wrlen×Wl from the right end.
The weight carried by a rod is the sum of the weights of every bead below it. Rods and strings weigh nothing, so they add nothing.