Matrix must die
Practice
5 (2 votes)
Linear algebra
Hard
Approved
Mathematics
Open
Matrix exponentiation
Problem
50% Success 398 Attempts 50 Points 2s Time Limit 256MB Memory 1024 KB Max Code

Let's call the following 3x3 integer matrix transformation an MMD-transformation in 0-based indexation:
Anew [i][j] = sum ( A[x][y] * f(i, j, x, y) ) through all pairs x, y from 0 to 2 where f(i, j, x, y) ) = |i - x| + |j - y| + |i + j - x - y|
You are given a 3x3 matrix A0. Let's denote by An matrix A0 after N MMD-transformations with elements modulo 109 + 7 . Your task is to find and output An.

Input
The first line contains T - the number of test cases. Then T test cases follow.
Each test case starts with line containing one integer N. Then 3 lines containing 3 integers each - matrix A0.

Output
For each test case output matrix An in 3 lines containing 3 integers each. Don't forget that elements should be found modulo 109 + 7.

Constraints

  • T30 000
  • Initial elements of matrix A are from 0 to 99
  • 1N1012
  • 1N20 in 30% of the test data.

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:50
Tags:
Dynamic ProgrammingLinear AlgebraHardMatrix ExponentiationAlgorithmsMathematicsOpenApproved
Points:20
42 votes
Tags:
AlgorithmsApprovedEasyGreedy AlgorithmsMathOpenSorting
Points:50
1 votes
Tags:
Dynamic ProgrammingLinear AlgebraHardMatrix ExponentiationAlgorithmsMathematicsOpenApproved