问题 I: WO MEI K

内存限制:256 MB 时间限制:3 S 标准输入输出
题目类型:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

There is a weighted tree with n vertices and n1 edges. each edge has a value. Let f(v,u) be the number of values that appear exactly once on the edges of a simple path between vertices v and u.

Now you randomly choose k vertices, which is x1,x2,,xk. For all k=1,2,,n, calculate the expectation of ek=i=1kj=i+1kf(xi,xj) modulo 998244353998244353

输入格式

This problem contains multiple test cases.The first line of input contains a single integer t(1t210^5)---the number of test cases.The description of test cases follows.

In a test, the first line contains a single integer n (2n210^5) --- the number of island

Each of the next n1 lines contains three integers v,u and x (1v,u,xn) --- This means that this egde connects u and v, and the value of this edge is x.

It's guarantee the sum of n over all test cases doesn't exceed 10^6.

输出格式

For each test case, print a single value X=e1e2en, where the note  denotes XOR by bit.

输入样例 复制

2
2
1 2 1
3
1 2 1
1 3 2

输出样例 复制

1
332748115