Colindăm Doamne colind

Time limit: 2s Memory limit: 256MB Input: Output:

Colindăm Doamne colind
Being lost in the mountains of Valea Jiului, Nicolae found one of the best problems he had seen. Upon reading it, he was filled with joy and started singing the beautiful ancient carol from above. Now he wants to share his discovery with you.

You are given an undirected connected weighted graph with NN nodes and MM edges. The graph is a cactus (i.e. each node is part of at most one cycle).

A trail in this graph is defined as a sequence of nodes a1,a2,a3,,aka_1, a_2, a_3, \dots, a_k such that there exists an edge between aia_i and ai+1a_{i+1} (1ik11 \le i \le k-1) and no edge is traversed more than once (note that nodes can be traversed more than once).

The cost of such a trail is the XOR of all the edges belonging to the trail.

Task

For QQ pairs of nodes (u,v)(u,v) you have to find the minimum cost of a trail that starts at uu and ends in vv.

Input data

The first line contains the numbers NN, MM and QQ.

The next MM lines each contain 3 integers aa, bb and cc, meaning there is an edge between aa and bb with cost cc.

The next QQ lines each contain 2 integers uu and vv, meaning a query with endpoints in uu and vv.

Output data

The output should contain QQ lines, the ii-th line containing the answer for the ii-th query.

Constraints and clarifications

  • 1N,Q1051 \le N, Q \le 10^5
  • N1M2105N-1 \le M \le 2 \cdot 10^5
  • The cost of any edge is at least 00 and strictly smaller than 2302^{30}.
  • The input graph does not contain multiple edges or self loops.

Example

stdin

10 11 10
10 1 226113825
1 6 646080092
7 9 363375133
8 2 412692880
4 7 493985477
5 1 616172447
7 2 313111157
4 2 256007221
3 1 814516487
2 1 627361906
10 6 549967887
6 8
10 2
2 9
7 10
9 3
1 4
9 6
2 2
4 5
2 9

stdout

272636108
589395489
117512296
823309521
309537176
555291445
75351747
0
87648303
117512296

Log in or sign up to be able to send submissions!