{"trustable":true,"prependHtml":"\u003cstyle type\u003d\u0027text/css\u0027\u003e\n .input, .output {\n border: 1px solid #888888;\n }\n .output {\n margin-bottom: 1em;\n position: relative;\n top: -1px;\n }\n .output pre, .input pre {\n background-color: #EFEFEF;\n line-height: 1.25em;\n margin: 0;\n padding: 0.25em;\n }\n \u003c/style\u003e\n \u003clink rel\u003d\"stylesheet\" href\u003d\"//codeforces.org/s/96598/css/problem-statement.css\" type\u003d\"text/css\" /\u003e\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 type\u003d\"text/javascript\" async src\u003d\"https://mathjax.codeforces.org/MathJax.js?config\u003dTeX-AMS_HTML-full\"\u003e\u003c/script\u003e","sections":[{"title":"","value":{"format":"HTML","content":"\u003cp\u003eThere is an undirected graph with $$$n$$$ vertices and $$$m$$$ edges. The vertices are labelled by $$$1,2,\\dots,n$$$. The $$$i$$$-th edge connects the $$$u_i$$$-th vertex and the $$$v_i$$$-th vertex, the length of which is $$$w_i$$$. Here, $$$u_i$$$\u0027s binary representation is always a prefix of $$$v_i$$$\u0027s binary representation. Both binary representations are considered without leading zeros. For example, $$$u_i\u003d2_{10}\u003d\\textbf{10}_2$$$, $$$v_i\u003d5_{10}\u003d\\textbf{10}1_{2}$$$.\u003c/p\u003e\u003cp\u003eYou will be given $$$q$$$ queries. In the $$$i$$$-th query, you will be given two integers $$$s_i$$$ and $$$t_i$$$. Please write a program to figure out the length of the shortest path from the $$$s_i$$$-th vertex to the $$$t_i$$$-th vertex, or determine there is no path between them.\u003c/p\u003e"}},{"title":"Input","value":{"format":"HTML","content":"\u003cp\u003eThe input contains only a single case.\u003c/p\u003e\u003cp\u003eThe first line of the input contains two integers $$$n$$$ and $$$m$$$ ($$$1 \\leq n \\leq 100\\,000$$$, $$$1\\leq m\\leq 200\\,000$$$), denoting the number of vertices and the number of edges.\u003c/p\u003e\u003cp\u003eIn the next $$$m$$$ lines, the $$$i$$$-th line $$$(1 \\le i \\le m)$$$ contains three integers $$$u_i,v_i$$$ and $$$w_i$$$ ($$$1\\le u_i\u0026lt;v_i\\leq n$$$, $$$1\\leq w_i\\leq 10^9$$$), describing the $$$i$$$-th edge. It is guaranteed that $$$u_i$$$\u0027s binary representation is a prefix of $$$v_i$$$\u0027s binary representation.\u003c/p\u003e\u003cp\u003eIn the next line, there contains a single integer $$$q$$$ ($$$1\\leq q\\leq 200\\,000$$$), denoting the number of queries.\u003c/p\u003e\u003cp\u003eIn the next $$$q$$$ lines, the $$$i$$$-th line $$$(1 \\le i \\le q)$$$ contains two integers $$$s_i$$$ and $$$t_i$$$ ($$$1\\leq s_i,t_i\\leq n$$$, $$$s_i\\neq t_i$$$), describing the $$$i$$$-th query.\u003c/p\u003e"}},{"title":"Output","value":{"format":"HTML","content":"\u003cp\u003eFor each query, print a single line containing an integer, denoting the length of the shortest path. If there is no path, print \"\u003cspan class\u003d\"tex-font-style-tt\"\u003e-1\u003c/span\u003e\" instead.\u003c/p\u003e"}},{"title":"Examples","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 6\n1 2 4\n1 3 2\n1 4 5\n1 5 8\n2 4 3\n2 5 2\n4\n2 3\n1 4\n1 5\n4 5\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e6\n5\n6\n5\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}},{"title":"","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 1\n1 2 100\n3\n1 2\n1 3\n2 3\n\u003c/pre\u003e\u003c/td\u003e\n \u003ctd\u003e\u003cpre\u003e100\n-1\n-1\n\u003c/pre\u003e\u003c/td\u003e\n \u003c/tr\u003e\n\u003c/tbody\u003e\n\u003c/table\u003e\n"}}]}