Road Repair

No attempts yetTime limit1sMemory limit256 MB

Problem

A city has a road network in which every road connects two districts. The network is a tree, so between any two districts there is exactly one path. A path here is the sequence of roads you travel along to get from one district to the other.

Many cars use the roads every day, so the roads wear out badly. The city transport department repairs them on a regular schedule. Every road RR has a cost cc and a benefit bb. Repairing RR costs cc and yields the social benefit bb.

Suppose you repair every road on a path. The cost of the path is the sum of the costs of its roads, and the benefit of the path is the sum of their benefits. Given an upper bound CC on cost, find a path whose cost is at most CC and whose benefit is as large as possible.

Input

Your program reads from standard input. The input holds TT test cases, and the first line gives TT.

The first line of each test case has nn, the number of districts in the network (2n220002 \le n \le 22000). The districts are numbered 11 through nn, and the network always has exactly n1n-1 roads. Each of the next n1n-1 lines has four integers α\alpha, β\beta, cc and bb, meaning that the road joining districts α\alpha and β\beta has cost cc and benefit bb (1α,βn1 \le \alpha, \beta \le n, 1c,b10001 \le c, b \le 1000). The last line gives the cost bound CC (1C2×1071 \le C \le 2 \times 10^7).

Output

Your program writes to standard output. Print one line for each test case. The line holds a single integer, the maximum benefit a path can obtain while its cost is at most CC. If no such path exists, print 00.