# Matrix Pain CodeChef Solution

### We Are Discuss About CODECHEF SOLUTION

Matrix Pain CodeChef Solution

## Matrix Pain CodeChef Solution ## Problem

Chef is here with another matrix  having  rows and  columns,
such that �(�,�)=(�−1)⋅�+�.

Chef decided to make this matrix interesting. He performed  operations on the matrix. In each operation, he will choose either a row or column and multiply all values in that row/column with a non-negative integer .

• An operation is of the form �,�,�:
• If �=0: Multiply each element of the ��ℎ row with .
• If �=1: Multiply each element of the ��ℎ column with .

Find the sum of all values in the matrix after all  operations are done. Since the value can be large, print it modulo 109+7.

### Input Format

• The first line of input will contain a single integer , denoting the number of test cases.
• Each test case consists of multiple lines of input.
• The first line of each test case contains three space-separated integers , and  — the number of rows, columns, and the operations to be done, respectively.
• The next  lines describe the operations. The ��ℎ of these  lines contain three space-separated integers ����, and ��, as mentioned in the statement.

### Output Format

For each test case, output on a new line, the sum of all elements of the matrix after performing the operations, modulo 109+7.

### Constraints

• 1≤�≤100
• 1≤�,�≤109
• 1≤�≤2⋅105
• 0≤��≤1
• 1≤�≤� if ��=0
• 1≤�≤� if ��=1
• 0≤��≤109
• The sum of  over all test cases won’t exceed 2⋅105

### Sample 1:

Input

Output

2
2 2 2
1 2 0
0 1 2
1 3 1
1 2 6
5
16


### Explanation:

Test case 1 : The initial matrix is [[1,2],[3,4]].

• In the first operation, multiply all elements of the second column with 0. Thus, the matrix becomes [[1,0],[3,0]].
• In the second operation, multiply all elements of the first row with 2. Thus, the matrix becomes [[2,0],[3,0]].

The sum of the elements of the updated matrix is 2+3=5.

Test case 2: The initial matrix is [[1,2,3]].

• In the first operation, multiply all elements of the second column with 6. Thus, the matrix becomes [[1,12,3]].

The sum of the elements of the updated matrix is 1+12+3=16. ## SOLUTION

Yhaa You have done it but next? if YOU Want to Get Others Please Visit Here ScishowEngineer   Then Follow US HERE and Join Telegram.