{"trustable":true,"sections":[{"title":"","value":{"format":"HTML","content":"Country Z has N cities, which are numbered from 1 to N. Cities are connected by highways, and there is exact one path between two different cities. Recently country Z often caught fire, so the government decided to build some firehouses in some cities. Build a firehouse in city K cost W(K). W for different cities may be different. If there is not firehouse in city K, the distance between it and the nearest city which has a firehouse, can’t be more than D(K). D for different cities also may be different. To save money, the government wants you to calculate the minimum cost to build firehouses."}},{"title":"Input","value":{"format":"HTML","content":"The first line of input contains a single integer T representing the number of test cases. The following T blocks each represents a test case.\r\u003cbr\u003e\r\u003cbr\u003eThe first line of each block contains an integer N (1 \u0026lt; N \u0026lt;\u003d 1000). The second line contains N numbers separated by one or more blanks. The I-th number means W(I) (0 \u0026lt; W(I) \u0026lt;\u003d 10000). The third line contains N numbers separated by one or more blanks. The I-th number means D(I) (0 \u0026lt;\u003d D(I) \u0026lt;\u003d 10000). The following N-1 lines each contains three integers u, v, L (1 \u0026lt;\u003d u, v \u0026lt;\u003d N,0 \u0026lt; L \u0026lt;\u003d 1000), which means there is a highway between city u and v of length L.\r\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each test case output the minimum cost on a single line."}},{"title":"Sample","value":{"format":"HTML","content":"\u003ctable class\u003d\u0027vjudge_sample\u0027\u003e\n\u003cthead\u003e\n \u003ctr\u003e\n \u003cth\u003eInput\u003c/th\u003e\n \u003cth\u003eOutput\u003c/th\u003e\n \u003c/tr\u003e\n\u003c/thead\u003e\n\u003ctbody\u003e\n \u003ctr\u003e\n \u003ctd\u003e\u003cpre\u003e5\r\n5\r\n1 1 1 1 1\r\n1 1 1 1 1\r\n1 2 1\r\n2 3 1\r\n3 4 1\r\n4 5 1\r\n5\r\n1 1 1 1 1\r\n2 1 1 1 2\r\n1 2 1\r\n2 3 1\r\n3 4 1\r\n4 5 1\r\n5\r\n1 1 3 1 1\r\n2 1 1 1 2\r\n1 2 1\r\n2 3 1\r\n3 4 1\r\n4 5 1\r\n4\r\n2 1 1 1\r\n3 4 3 2\r\n1 2 3\r\n1 3 3\r\n1 4 2\r\n4\r\n4 1 1 1\r\n3 4 3 2\r\n1 2 3\r\n1 3 3\r\n1 4 2\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e2\r\n1\r\n2\r\n2\r\n3\r\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}