Pangaea 2

No attempts yetTime limit20sMemory limit256 MB

Problem

In the beginning the world had nn cities and n1n - 1 roads joining them. Each city carries an integer label between 00 and n1n - 1. Every road can be travelled in both directions and joins two different cities. In that first world you could walk from any city to every other city along one or more roads.

Humans gained wisdom and built a brilliant civilization, yet laying a new road between two cities was the one thing they never managed.

The creator watched this and began laying one road between two cities every year. The creator also wondered whether humans had the intelligence that the new roads deserve, so the creator posed this puzzle.

Every time a road is laid, choose some of the roads laid so far so that all cities are joined to each other directly or indirectly, and make the total length of the chosen roads as small as possible.

The humans who received the puzzle decided to solve it and show the creator that they deserve to use the roads. Nobody knows what a disappointed creator would do if they failed. You represent humankind, so you have to survive the trial the creator set.

Input

The first line contains the number of test cases TT. The first line of each test case contains the number of cities nn and the number of roads laid by the creator mm, separated by a space (1n,m1000001 \le n, m \le 100\,000).

The next n1n - 1 lines describe the first world. Line ii (1in11 \le i \le n - 1) contains two integers ui,ciu_i, c_i (0ui<i0 \le u_i < i, 0ci100000000 \le c_i \le 10\,000\,000) separated by a space, which means city ii and city uiu_i are joined by a road of length cic_i.

The next mm lines describe the roads the creator laid, in the order they were laid. Line jj (1jm1 \le j \le m) contains three integers uj,vj,cju_j, v_j, c_j (0uj,vj<n0 \le u_j, v_j < n, 0cj100000000 \le c_j \le 10\,000\,000) separated by spaces, which means the jj-th road the creator laid joins city uju_j and city vjv_j and has length cjc_j. uju_j and vjv_j may be equal, and the road may join two cities that a road already joins.

Output

Print one line for each test case. The line contains the XOR of all mm answers, one answer for each road the creator laid.