Determination

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

문제

Chiaki has an n×nn \times n matrix MM defined as follows.

  1. M_i,i=d_iM\_{i, i} = d\_i for each i1,2,,ni \in \\{1, 2, \dots, n\\},
  2. M_p_i,i=a_iM\_{p\_i, i} = a\_i, M_i,p_i=b_iM\_{i, p\_i} = b\_i for each i2,3,,ni \in \\{2, 3, \dots, n\\},
  3. M_i,j=xM\_{i, j} = x, otherwise.

Given the value of d_id\_i, p_ip\_i, a_ia\_i, b_ib\_i and xx, find det(M)\mathrm{det}(M) modulo (109+7)(10^9+7).

입력

There are multiple test cases. The first line of the input contains an integer TT (1T1061 \le T \le 10^6), indicating the number of test cases. For each test case:

The first line contains two integers nn and xx (1n1061 \leq n \leq 10^6, 0x1090 \leq x \leq 10^9). The second line contains nn integers d_1,d_2,,d_nd\_1, d\_2, \dots, d\_n (0d_i1090 \leq d\_i \leq 10^9). The ii-th of the following (n1)(n - 1) lines contains three integers p_i+1,a_i+1,b_i+1p\_{i + 1}, a\_{i + 1}, b\_{i + 1} (1p_i+1i1 \leq p\_{i + 1} \leq i, 0a_i+1,b_i+11090 \leq a\_{i + 1}, b\_{i + 1} \leq 10^9). 

The sum of all nn does not exceed 10610^6.

출력

For each test case, output an integer denoting the answer.