{"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 houses in the village and some bidirectional roads connecting them. Every day peole always like to ask like this \"How far is it if I want to go from house A to house B\"? Usually it hard to answer. But luckily int this village the answer is always unique, since the roads are built in the way that there is a unique simple path(\"simple\" means you can\u0027t visit a place twice) between every two houses. Yout task is to answer all these curious people.\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"First line is a single integer T(T\u0026lt;\u003d10), indicating the number of test cases.\u003cbr\u003e\u0026nbsp;\u0026nbsp;For each test case,in the first line there are two numbers n(2\u0026lt;\u003dn\u0026lt;\u003d40000) and m (1\u0026lt;\u003dm\u0026lt;\u003d200),the number of houses and the number of queries. The following n-1 lines each consisting three numbers i,j,k, separated bu a single space, meaning that there is a road connecting house i and house j,with length k(0\u0026lt;k\u0026lt;\u003d40000).The houses are labeled from 1 to n.\u003cbr\u003e\u0026nbsp;\u0026nbsp;Next m lines each has distinct integers i and j, you areato answer the distance between house i and house j."}},{"title":"Output","value":{"format":"HTML","content":"For each test case,output m lines. Each line represents the answer of the query. Output a bland line after each test case."}},{"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\u003e2\r\n3 2\r\n1 2 10\r\n3 1 15\r\n1 2\r\n2 3\r\n\r\n2 2\r\n1 2 100\r\n1 2\r\n2 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e10\r\n25\r\n100\r\n100\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}