{"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$ intersections in Bytetown, connected with $m$ one way streets. Little Q likes sport walking very much, he plans to walk for $q$ days. On the $i$-th day, Little Q plans to start walking at the $s_i$-th intersection, walk through at least $k_i$ streets and finally return to the $t_i$-th intersection.\u003cbr\u003eLittle Q\u0027s smart phone will record his walking route. Compared to stay healthy, Little Q cares the statistics more. So he wants to minimize the total walking length of each day. Please write a program to help him find the best route.\u003cbr\u003e\u003c/div\u003e"}},{"title":"Input","value":{"format":"HTML","content":"The first line of the input contains an integer $T(1\\leq T\\leq10)$, denoting the number of test cases.\u003cbr\u003eIn each test case, there are $2$ integers $n,m(2\\leq n\\leq 50,1\\leq m\\leq 10000)$ in the first line, denoting the number of intersections and one way streets.\u003cbr\u003eIn the next $m$ lines, each line contains $3$ integers $u_i,v_i,w_i(1\\leq u_i,v_i\\leq n,u_i\\neq v_i,1\\leq w_i\\leq 10000)$, denoting a one way street from the intersection $u_i$ to $v_i$, and the length of it is $w_i$.\u003cbr\u003eThen in the next line, there is an integer $q(1\\leq q\\leq 100000)$, denoting the number of days.\u003cbr\u003eIn the next $q$ lines, each line contains $3$ integers $s_i,t_i,k_i(1\\leq s_i,t_i\\leq n,1\\leq k_i\\leq 10000)$, describing the walking plan.\u003cbr\u003e"}},{"title":"Output","value":{"format":"HTML","content":"For each walking plan, print a single line containing an integer, denoting the minimum total walking length. If there is no solution, please print -1.\u003cbr\u003e"}},{"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\t\t\r\n3 3\t\r\n1 2 1\r\n2 3 10\r\n3 1 100\r\n3\t\t\r\n1 1 1\r\n1 2 1\r\n1 3 1\r\n2 1\t\r\n1 2 1\r\n1\t\t\r\n2 1 1\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e111\r\n1\r\n11\r\n-1\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}