Cactus

아직 제출이 없습니다시간 제한2초메모리 제한512 MB

문제

A cactus graph is a connected undirected graph without self-loops and multiple edges in which each edge belongs to at most one simple cycle.

Given is a cactus graph GG with NN vertices, numbered from 11 to NN, and MM edges. The ii-th edge connects vertices a_ia\_i and b_ib\_i, and its cost is c_ic\_i.

Let the cost of a simple path on graph GG be bitwise XOR of the costs of all the edges on that path.

Answer QQ queries of the form "x_ix\_i y_iy\_i k_ik\_i}': consider the costs of all simple paths connecting vertices x_ix\_i and y_iy\_i, remove duplicate values, sort the values in ascending order, and take k_ik\_i-th element. If the number of these values is less than k_ik\_i, answer 1-1.

입력

The first line of the input contains two integers NN and MM: the number of vertices and the number of edges in the graph (2N1052 \le N \le 10^5, N1M2105N-1 \le M \le 2 \cdot 10^5).

Each of the next MM lines describes one edge and contains three integers a_ia\_i, b_ib\_i and c_ic\_i (1a_i,b_iN1 \le a\_i, b\_i \le N, a_ib_ia\_i \ne b\_i, 0c_i<2300 \le c\_i < 2^{30}).

Then follows a line containing an integer QQ: the number of queries (1q21051 \le q \le 2 \cdot 10^5).

Each of the next QQ lines describes one query and contains three integers x_ix\_i, y_iy\_i and k_ik\_i (1x_i,y_iN1 \le x\_i, y\_i \le N, x_iy_ix\_i \ne y\_i, 1k_i2301 \le k\_i \le 2^{30}).

It is guaranteed that the graph given in the input is a cactus graph.

출력

For each query, print one integer on a separate line: the answer to that query.