Chiaki has an n×n matrix M defined as follows.
Given the value of d_i, p_i, a_i, b_i and x, find det(M) modulo (109+7).
There are multiple test cases. The first line of the input contains an integer T (1≤T≤106), indicating the number of test cases. For each test case:
The first line contains two integers n and x (1≤n≤106, 0≤x≤109). The second line contains n integers d_1,d_2,…,d_n (0≤d_i≤109). The i-th of the following (n−1) lines contains three integers p_i+1,a_i+1,b_i+1 (1≤p_i+1≤i, 0≤a_i+1,b_i+1≤109).
The sum of all n does not exceed 106.
For each test case, output an integer denoting the answer.