{"raw_statement":[{"iden":"problem statement","content":"We have a connected undirected graph with $N$ vertices numbered $1$ to $N$ and $M$ edges numbered $1$ to $M$. Edge $i$ connects vertex $U_i$ and vertex $V_i$, and has an integer weight of $W_i$. For $1\\leq s,t \\leq N,\\ s\\neq t$, let us define $d(s,t)$ as follows.\n\n*   For every path connecting vertex $s$ and vertex $t$, consider the maximum weight of an edge along that path. $d(s,t)$ is the minimum value of this weight.\n\nAnswer $Q$ queries. The $j$\\-th query is as follows.\n\n*   You are given $A_j,S_j,T_j$. By what value will $d(S_j,T_j)$ increase when the weight of edge $A_j$ is increased by $1$?\n\nNote that each query does not actually change the weight of the edge."},{"iden":"constraints","content":"*   $2\\leq N \\leq 2\\times 10^5$\n*   $N-1\\leq M \\leq 2\\times 10^5$\n*   $1 \\leq U_i,V_i \\leq N$\n*   $U_i \\neq V_i$\n*   $1 \\leq W_i \\leq M$\n*   The given graph is connected.\n*   $1\\leq Q \\leq 2\\times 10^5$\n*   $1 \\leq A_j \\leq M$\n*   $1 \\leq S_j,T_j \\leq N$\n*   $S_j\\neq T_j$\n*   All values in the input are integers."},{"iden":"input","content":"The input is given from Standard Input in the following format:\n\n$N$ $M$\n$U_1$ $V_1$ $W_1$\n$\\vdots$\n$U_M$ $V_M$ $W_M$\n$Q$\n$A_1$ $S_1$ $T_1$\n$\\vdots$\n$A_Q$ $S_Q$ $T_Q$"},{"iden":"sample input 1","content":"6 6\n1 2 1\n3 1 5\n4 1 5\n3 4 3\n5 6 4\n2 6 5\n7\n1 4 6\n2 4 6\n3 4 6\n4 4 6\n5 4 6\n6 4 6\n5 6 5"},{"iden":"sample output 1","content":"0\n0\n0\n0\n0\n1\n1\n\n![image](https://img.atcoder.jp/abc301/00609898872063e16f2e7b43c6436c6d.png)\nThe above figure shows the edge numbers in black and the edge weights in blue.\nLet us explain the first through sixth queries.\nFirst, consider $d(4,6)$ in the given graph. The maximum weight of an edge along the path $4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 6$ is $5$, which is the minimum over all paths connecting vertex $4$ and vertex $6$, so $d(4,6)=5$.\nNext, consider the increment of $d(4,6)$ when the weight of edge $x\\ (1 \\leq x \\leq 6)$ increases by $1$. When $x=6$, we have $d(4,6)=6$, and the increment is $1$. On the other hand, when $x \\neq 6$, we have $d(4,6)=5$, and the increment is $0$. For instance, when $x=3$, the maximum weight of an edge along the path $4 \\rightarrow 1 \\rightarrow 2 \\rightarrow 6$ is $6$, but the maximum weight of an edge along the path $4 \\rightarrow 3 \\rightarrow 1 \\rightarrow 2 \\rightarrow 6$ is $5$, so $d(4,6)$ is still $5$."},{"iden":"sample input 2","content":"2 2\n1 2 1\n1 2 1\n1\n1 1 2"},{"iden":"sample output 2","content":"0\n\nThe given graph may contain multi-edges."}],"translated_statement":null,"sample_group":[],"show_order":["default"],"formal_statement":null,"simple_statement":null,"has_page_source":true}