#P9837. WO MEI K
WO MEI K
WO MEI K
Problem Description
There is a weighted tree with vertices and edges. each edge has a value. Let be the number of values that appear exactly once on the edges of a simple path between vertices and . Now you randomly choose vertices, which is . For all , calculate the expectation of modulo
Input
This problem contains multiple test cases.The first line of input contains a single integer ---the number of test cases.The description of test cases follows. In a test, the first line contains a single integer () --- the number of island Each of the next lines contains three integers and () --- This means that this egde connects and , and the value of this edge is . It's guarantee the sum of over all test cases doesn't exceed .
Output
For each test case, print a single value , where the note denotes XOR by bit.
Sample Input
2
2
1 2 1
3
1 2 1
1 3 2
Sample Output
1
332748115
Source
2023“钉耙编程”中国大学生算法设计超级联赛(4)