Server Time: Wed Feb 26, 2020 1:41 pm
Welcome ( logout
B - Summing up Powers (II)
PDF (English) Ranklist
Time Limit: 2 second(s) Memory Limit: 32 MB

Shanto is learning how to power up numbers and he found an efficient way to find kth power of a matrix. He was quite happy with his discovery. Suddenly his sister Natasha came to him and asked him to find the summation of the powers. To be specific his sister gave the following problem.

Let A be an n x n matrix. We define Ak = A * A * ... * A (k times). Here, * denotes the usual matrix multiplication. You are to write a program that computes the matrix A + A2 + A3 + ... + Ak.

Shanto smiled and thought that it would be an easy one. But after a while he found that it's tough for him. Can you help him?

Input

Input starts with an integer T (≤ 20), denoting the number of test cases.

Each case starts with two integers n (1 ≤ n ≤ 30) and k (1 ≤ k ≤ 109). Each of the next n lines will contain n non-negative integers (not greater than 10).

Output

For each case, print the case number and the result matrix. For each cell, just print the last digit. See the samples for more details.

Sample Input

Output for Sample Input

2

3 2

1 4 6

6 5 2

1 2 3

3 10

1 4 6

6 5 2

1 2 3

Case 1:

208

484

722

Case 2:

868

620

546

 


Problem Setter: Jane Alam Jan
Developed and Maintained by
JANE ALAM JAN
Copyright © 2012
LightOJ, Jane Alam Jan