{"trustable":true,"prependHtml":"\u003cscript\u003e window.katexOptions \u003d { disable: true }; \u003c/script\u003e\n\u003cscript type\u003d\"text/x-mathjax-config\"\u003e\n MathJax.Hub.Config({\n tex2jax: {\n inlineMath: [[\u0027$$$\u0027,\u0027$$$\u0027], [\u0027$\u0027,\u0027$\u0027]],\n displayMath: [[\u0027$$$$$$\u0027,\u0027$$$$$$\u0027], [\u0027$$\u0027,\u0027$$\u0027]]\n }\n });\n\u003c/script\u003e\n\u003cscript async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS-MML_HTMLorMML\" type\u003d\"text/javascript\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cdiv class\u003d\"panel_content\"\u003eThere are $N$ vertices connected by $N-1$ edges, each edge has its own length.\u003cbr\u003eThe set { $1, 2, 3, … , N$ } contains a total of $N!$ unique permutations, let’s say the $i$-th permutation is $P_i$ and $P_{i,j}$ is its $j$-th number.\u003cbr\u003eFor the $i$-th permutation, it can be a traverse sequence of the tree with $N$ vertices, which means we can go from the $P_{i,1}$-th vertex to the $P_{i,2}$-th vertex by the shortest path, then go to the $P_{i,3}$-th vertex ( also by the shortest path ) , and so on. Finally we’ll reach the $P_{i,N}$-th vertex, let’s define the total distance of this route as $D(P_i)$ , so please calculate the sum of $D(P_i)$ for all $N!$ permutations.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"There are 10 test cases at most.\u003cbr\u003eThe first line of each test case contains one integer $N$ ( $1 ≤ N ≤ 10^5$ ) .\u003cbr\u003eFor the next $N-1$ lines, each line contains three integer $X$, $Y$ and $L$, which means there is an edge between $X$-th vertex and $Y$-th of length $L$ ( $1 ≤ X, Y ≤ N, 1 ≤ L ≤ 10^9$ ) ."}},{"title":"Output","value":{"format":"HTML","content":"For each test case, print the answer module $10^9+7$ in one 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\u003e3\r\n1 2 1\r\n2 3 1\r\n3\r\n1 2 1\r\n1 3 2\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e16\r\n24\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}