{"trustable":false,"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":"MD","content":" There are $n$ houses in the village and some bidirectional roads connecting them.\n\nEvery day people 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 in 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.\n\nYour task is to answer all these curious people."}},{"title":"Input","value":{"format":"MD","content":"First line is a single integer $T(T\\leq 10)$, indicating the number of test cases. For each test case:\n\nIn the first line there are two integers $n(2\\leq n\\leq 40000)$ and $m (1\\leq m\\leq 200)$, the number of houses and the number of queries. \n\nThe following $n-1$ lines each consisting three numbers $i,j,k$, meaning that there is a road connecting house $i$ and house $j$, with length $k(0\\leq k\\leq40000)$. The houses are labeled from $1$ to $n$.\n\nNext $m$ lines each has distinct integers $i$ and $j$, you need answer the distance between house $i$ and house $j$."}},{"title":"Output","value":{"format":"MD","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":"MD","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\u003e\u003cpre\u003e2\n3 2\n1 2 10\n3 1 15\n1 2\n2 3\n\n2 2\n1 2 100\n1 2\n2 1\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e\u003cpre\u003e10\n25\n100\n100\u003c/pre\u003e\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}