Inner Product

아직 제출이 없습니다시간 제한3초메모리 제한256 MB

문제

Chiaki has two trees and each tree has nn vertices, labeled by 1,2,,n1, 2, \ldots, n. Consider the following two arrays A=\[d_1(1,1),d_1(1,2),,d_1(1,n),d_1(2,1),d_1(2,2),,d_1(2,n),,d_1(n,1),d_1(n,2),,d_1(n,n)]A = \[d\_1(1, 1), d\_1(1, 2), \ldots, d\_1(1, n), d\_1(2, 1), d\_1(2, 2), \ldots, d\_1(2, n), \ldots, d\_1(n, 1), d\_1(n, 2), \ldots, d\_1(n, n)], B=\[d_2(1,1),d_2(1,2),,d_2(1,n),d_2(2,1),d_2(2,2),,d_2(2,n),,d_2(n,1),d_2(n,2),,d_2(n,n)]B = \[d\_2(1, 1), d\_2(1, 2), \ldots, d\_2(1, n), d\_2(2, 1), d\_2(2, 2), \ldots, d\_2(2, n), \ldots, d\_2(n, 1), d\_2(n, 2), \ldots, d\_2(n, n)], where d_1(i,j)d\_1(i, j) is the distance between ii and jj on the first tree, and d_2(i,j)d\_2(i, j) is the distance between ii and jj on the second tree.

Chiaki would like to know the inner product of AA and BB. By the way, the inner product of two arrays a=\[a_1,a_2,,a_m]a = \[a\_1, a\_2, \ldots, a\_m] and b=\[b_1,b_2,,b_m]b = \[b\_1, b\_2, \ldots, b\_m] is defined as _k=1ma_kb_k\sum\_{k = 1}^{m}{a\_k b\_k}.

입력

There are multiple test cases. The first line of the input contains an integer TT, indicating the number of test cases. For each test case:

The first line contains an integer nn (1n1051 \le n \le 10^5) --- the number of vertices in each tree.

Each of the next (n1)(n - 1) lines contains three integers u_iu\_i, v_iv\_i and w_iw\_i (1u_i,v_in1 \le u\_i, v\_i \le n, 1w_i1091 \le w\_i \le 10^9) --- an edge of length w_iw\_i between vertices u_iu\_i and v_iv\_i on the first tree.

Each of the next (n1)(n - 1) lines contains three integers u_iu\_i, v_iv\_i and w_iw\_i (1u_i,v_in1 \le u\_i, v\_i \le n, 1w_i1091 \le w\_i \le 10^9) --- an edge of length w_iw\_i between vertices u_iu\_i and v_iv\_i on the second tree.

It is guaranteed that the sum of nn in all test cases will not exceed 10510^5.

출력

For each test case, output an integer in a single line, denoting the inner product of AA and BB modulo (109+7)(10^9 + 7).