There are multiple test cases in the input file. Each test case starts with a single number n (0<=n<=500) , which is the number of caves, followed by n - 1 lines describing the map. Each of the n - 1 lines contains three integers separated by blanks: i , j , and d (1<=d<=10000) . It means that the i -th cave's parent cave is the j -th cave and the distance is d meters. A parent cave of cave i is the first cave to enter on the path from i to the main cave. Caves are numbered from 0 to n - 1 . Then there is an integer q (1<=q<=1000) , which is the number of queries, followed by q lines. For one query, there is one integer x (0<=x<=5000000) , the maximum distance that the robot can travel. n = 0 indicates the end of input file.