In the beginning the world had n cities and n−1 roads joining them. Each city carries an integer label between 0 and n−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.
The first line contains the number of test cases T. The first line of each test case contains the number of cities n and the number of roads laid by the creator m, separated by a space (1≤n,m≤100000).
The next n−1 lines describe the first world. Line i (1≤i≤n−1) contains two integers ui,ci (0≤ui<i, 0≤ci≤10000000) separated by a space, which means city i and city ui are joined by a road of length ci.
The next m lines describe the roads the creator laid, in the order they were laid. Line j (1≤j≤m) contains three integers uj,vj,cj (0≤uj,vj<n, 0≤cj≤10000000) separated by spaces, which means the j-th road the creator laid joins city uj and city vj and has length cj. uj and vj may be equal, and the road may join two cities that a road already joins.
Print one line for each test case. The line contains the XOR of all m answers, one answer for each road the creator laid.