There are $n$ children, numbered $1,2,\ldots,n$, sitting around a circle in a clockwise manner. The ${i}$th child has a piece of paper with the number $a_i$ written on it. They play the following game:

In the ${1}$st round, the child numbered ${i}$ increases his number by the sum of the numbers of his neighbors.  
In the $2$nd round, the child next in clockwise order increases his number by the sum of the numbers of his neighbors.
In the $3$rd round, the child next in clockwise order increases his number by the sum of the numbers of his neighbors.
And so on.  

The game ends after $m$ rounds have been played.  

For every ${i}$, find the numbers that the children end up with if the game starts with child ${i}$ playing the first round. Since the numbers can be large, output them modulo $10^9+7$.  

Input Format

The first line contains ${t}$, the number of test cases. ${t}$ cases follow.  

The first line of each test case contains two space-separated integers $n$ and $m$. The next line contains $n$ integers, the ${i}$th of which is $a_i$.  

Constraints

$1\leq t\leq15$  
$3\leq n\leq50$  
$1\leq m\leq10^9$  
$1\leq a_i\leq10^9$  

Output Format

For each test case, print $n$ lines, each having $n$ integers. The $j$th integer on the ${i}$th line contains the number that the $j$th child ends up with if the game starts with child ${i}$ playing the first round.  

Print a blank line after each test case except the last one.  

Since the numbers can be large, output them modulo $10^9+7$.  

Sample Input 0
2
5 1
10 20 30 40 50
3 4
1 2 1

Sample Output 0
80 20 30 40 50
10 60 30 40 50
10 20 90 40 50
10 20 30 120 50
10 20 30 40 100

23 7 12
11 21 6
7 13 24

Difficulty: HARD

Solutions:
import functools

def intmatvecmul(M, v, N, mod):
	out = []
	for i in range(N):
		acc = 0
		for j in range(N):
			acc = (acc + M[i][j] * v[j]) % mod
		out.append(acc)
	return out

def intmatmul(A, B, N, mod):
	out = []
	for i in range(N):
		row = []
		for j in range(N):
			acc = 0
			for k in range(N):
				acc = (acc + A[i][k] * B[k][j]) % mod
			row.append(acc)
		out.append(row)
	return out

def eye(N):
	out = []
	for i in range(N):
		row = []
		for j in range(N):
			if i == j:
				row.append(1)
			else:
				row.append(0)
		out.append(row)
	return out

def intmatpow(A, pwr, N, mod):
	tmp = A
	k = 1
	if pwr % 2 == 1:
		pwr -= 1
		acc = A
	else:
		acc = []
	while pwr > 0:
		tmp = intmatmul(tmp, tmp, N, mod)
		if pwr % 2 ** (k + 1) != 0:
			pwr -= 2 ** k
			if acc:
				acc = intmatmul(acc, tmp, N, mod)
			else:
				acc = tmp
		k += 1
	return acc
T = int(input())
for q in range(T):
	NM = [int(x) for x in input().split()]
	N = NM[0]
	M = NM[1]

	def nxt(i):
		if i == N - 1:
			return 0
		else:
			return i + 1

	def prev(i):
		if i == 0:
			return N - 1
		else:
			return i - 1
	stepmatrices = []
	for i in range(N):
		m = eye(N)
		m[i][prev(i)] = 1
		m[i][nxt(i)] = 1
		stepmatrices.append(m)
	Nstepmatrix = eye(N)
	for i in range(N):
		for j in range(N):
			Nstepmatrix[i][j] += Nstepmatrix[(i - 1) % N][j] + Nstepmatrix[(i + 1) % N][j]
	numbigsteps = M // N - 1
	numsmallsteps = M % N + N
	hugestepmatrix = intmatpow(Nstepmatrix, numbigsteps, N, 1000000007)
	ai = [int(x) for x in input().strip().split()]
	for x in range(N):
		state = ai.copy()
		if numbigsteps >= 1:
			for i in range(x, N):
				state[i] = (state[i] + state[prev(i)] + state[nxt(i)]) % 1000000007
			state = intmatvecmul(hugestepmatrix, state, N, 1000000007)
			for i in range(numsmallsteps - N + x):
				state[i % N] = (state[i % N] + state[(i - 1) % N] + state[(i + 1) % N]) % 1000000007
		else:
			count = 0
			i = x
			while count < M:
				state[i % N] = (state[i % N] + state[(i - 1) % N] + state[(i + 1) % N]) % 1000000007
				count += 1
				i = nxt(i)
		print(' '.join(map(str, state)))
	print()


import functools

def intmatvecmul(M, v, N, mod):
	out = []
	for i in range(N):
		acc = 0
		for j in range(N):
			acc = (acc + M[i][j] * v[j]) % mod
		out.append(acc)
	return out

def intmatmul(A, B, N, mod):
	out = []
	for i in range(N):
		row = []
		for j in range(N):
			acc = 0
			for k in range(N):
				acc = (acc + A[i][k] * B[k][j]) % mod
			row.append(acc)
		out.append(row)
	return out

def eye(N):
	out = []
	for i in range(N):
		row = []
		for j in range(N):
			if i == j:
				row.append(1)
			else:
				row.append(0)
		out.append(row)
	return out

def intmatpow(A, pwr, N, mod):
	tmp = A
	k = 1
	if pwr % 2 == 1:
		pwr -= 1
		acc = A
	else:
		acc = []
	while pwr > 0:
		tmp = intmatmul(tmp, tmp, N, mod)
		if pwr % 2 ** (k + 1) != 0:
			pwr -= 2 ** k
			if acc:
				acc = intmatmul(acc, tmp, N, mod)
			else:
				acc = tmp
		k += 1
	return acc
T = int(input())
for q in range(T):
	NM = [int(x) for x in input().split()]
	N = NM[0]
	M = NM[1]

	def nxt(i):
		if i == N - 1:
			return 0
		else:
			return i + 1

	def prev(i):
		if i == 0:
			return N - 1
		else:
			return i - 1
	stepmatrices = []
	for i in range(N):
		m = eye(N)
		m[i][prev(i)] = 1
		m[i][nxt(i)] = 1
		stepmatrices.append(m)
	Nstepmatrix = eye(N)
	for i in range(N):
		for j in range(N):
			Nstepmatrix[i][j] += Nstepmatrix[(i - 1) % N][j] + Nstepmatrix[(i + 1) % N][j]
	numbigsteps = M // N - 1
	numsmallsteps = M % N + N
	hugestepmatrix = intmatpow(Nstepmatrix, numbigsteps, N, 1000000007)
	ai = [int(x) for x in input().strip().split()]
	for x in range(N):
		state = ai.copy()
		if numbigsteps >= 1:
			for i in range(x, N):
				state[i] = (state[i] + state[prev(i)] + state[nxt(i)]) % 1000000007
			state = intmatvecmul(hugestepmatrix, state, N, 1000000007)
			for i in range(numsmallsteps - N + x):
				state[i % N] = (state[i % N] + state[(i - 1) % N] + state[(i + 1) % N]) % 1000000007
		else:
			count = 0
			i = x
			while count < M:
				state[i % N] = (state[i % N] + state[(i - 1) % N] + state[(i + 1) % N]) % 1000000007
				count += 1
				i = nxt(i)
		print(' '.join(map(str, state)))
	print()


def productList(L):
	X = L[0].copy()
	for i in range(1, len(L)):
		X = productMatrix(X, L[i])
	return X

def productMatrix(A, B):
	BB = transpose(B)
	return [[sum([x * y for (x, y) in zip(A[i], BB[j])]) for j in range(len(B[0]))] for i in range(len(A))]

def transpose(X):
	return [[X[i][j] for i in range(len(X))] for j in range(len(X[0]))]

def productMatrixVector(X, a, mod):
	return [sum([x * y for (x, y) in zip(X[i], a)]) % mod for i in range(len(X))]

def createMatList(n, k):
	kk = k - 1
	L = []
	S = []
	for j in range(n):
		X = [[0 for _ in range(n)] for _ in range(n)]
		Y = [[0 for _ in range(n)] for _ in range(n)]
		for i in range(n):
			X[i][i] = 1
			Y[i][i] = 1
			if i == kk:
				X[i][(i - 1) % n] = 1
				X[i][(i + 1) % n] = 1
				Y[i][(i - 1) % n] = -1
				Y[i][(i + 1) % n] = -1
		L.append(X)
		S.append(Y)
		kk = (kk + 1) % n
	return (L, S)

def modMatrix(X, m):
	return [[c % m for c in l] for l in X]

def fastMatExp(X, e, m):
	result = [[1 if i == j else 0 for i in range(len(X))] for j in range(len(X))]
	while e > 0:
		if e & 1 > 0:
			result = modMatrix(productMatrix(result, X), m)
		e >>= 1
		X = modMatrix(productMatrix(X, X), m)
	return result

def createGenMatrix(n, q):
	result = [[1 if i == j else 0 for i in range(n)] for j in range(n)]
	result2 = [[1 if i == j else 0 for i in range(n)] for j in range(n)]
	result[0][1] = result[0][-1] = 1
	if q > 0:
		result2[0][1] = result2[0][-1] = 1
	for i in range(1, n - 1):
		result[i] = result[i - 1].copy()
		result[i][i] += 1
		result[i][i + 1] += 1
		if i < q:
			result2[i] = result2[i - 1].copy()
			result2[i][i] += 1
			result2[i][i + 1] += 1
	result[-1] = result[-2].copy()
	result[-1][0] = 2
	result[-1][1] = 3
	result[-1][-1] = 4
	return (result, result2)
mod = 1000000007
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	(L, S) = createMatList(n, 1)
	(P, R) = createGenMatrix(n, m % n)
	X = fastMatExp(P, m // n, mod)
	X = productMatrix(R, X)
	q = m % n
	for i in range(1, n + 1):
		A = a.copy()
		for j in range(i - 1, 0, -1):
			A = productMatrixVector(S[j - 1], A, mod)
		A = productMatrixVector(X, A, mod)
		for j in range(1, i):
			A = productMatrixVector(L[(j - 1 + q) % n], A, mod)
		print(*A)
	if _ < t - 1:
		print('')


import os, sys

def power_peasant_3(a, n, mult3, unity):
	adim = len(a)
	prod = unity
	tmp = [[0] * adim for _ in range(adim)]
	pwr = a
	while n != 0:
		if n % 2 != 0:
			mult3(tmp, prod, pwr)
			(tmp, prod) = (prod, tmp)
		n >>= 1
		if n == 0:
			break
		mult3(tmp, pwr, pwr)
		(tmp, pwr) = (pwr, tmp)
	return prod

def matrix_unit(n):
	return [[1 if col == row else 0 for col in range(n)] for row in range(n)]

def matrix_mod_product_3(m, dest, A, B):
	n = len(dest)
	for row in range(n):
		for col in range(n):
			(s, arow) = (0, A[row])
			for i in range(n):
				s += arow[i] * B[i][col]
			dest[row][col] = s % m

def matrix_mod_apply(m, A, v):
	n = len(A)
	res = [0] * n
	for row in range(n):
		(s, arow) = (0, A[row])
		for i in range(n):
			s += arow[i] * v[i]
		res[row] = s % m
	return res
MOD = 10 ** 9 + 7

def circle_map(a, n, k):
	a[k] = (a[k] + a[(k - 1) % n] + a[(k + 1) % n]) % MOD

def circle_sum(a, m):
	n = len(a)
	A = []
	for k in range(n):
		if k == 0:
			row = [0] * n
			row[n - 1] = row[0] = row[1] = 1
		elif k == n - 1:
			row = A[k - 1].copy()
			for i in range(n):
				row[i] += A[0][i]
			row[k] += 1
		else:
			row = A[k - 1].copy()
			row[k] += 1
			row[(k + 1) % n] += 1
		A.append(row)
	mn = m // n
	if mn >= 3:
		mn -= 2
		mn2 = mn * n
		unity = matrix_unit(n)

		def mult3(dst, A, B):
			return matrix_mod_product_3(MOD, dst, A, B)
		Ap = power_peasant_3(A, mn, mult3, unity)
	else:
		mn = 0
	res = []
	for i in range(n):
		b = a.copy()
		k = 0
		for _ in range(min(m, n - i)):
			circle_map(b, n, (i + k) % n)
			k += 1
		if mn >= 1:
			b = matrix_mod_apply(MOD, Ap, b)
			k += mn2
		r2 = m - k
		assert r2 >= 0
		for _ in range(r2):
			circle_map(b, n, (i + k) % n)
			k += 1
		res.append(b)
	if False and m % n == 0:
		unity = matrix_unit(n)

		def mult3(dst, A, B):
			return matrix_mod_product_3(MOD, dst, A, B)
		Am = power_peasant_3(A, m // n, mult3, unity)
		print('** TEST: row0', m // n, matrix_mod_apply(MOD, Am, a))
	for row in res:
		print(' '.join(map(str, row)))

def main():
	ncases = int(sys.stdin.readline())
	for ti in range(ncases):
		(n, m) = list(map(int, sys.stdin.readline().split()))
		a = list(map(int, sys.stdin.readline().split()))
		if ti > 0:
			print()
		circle_sum(a, m)
main()


modulo_constant = 10 ** 9 + 7

def mx_times(a, b, mo):
	return [[sum((a * b for (a, b) in zip(a_row, b_col))) % mo for b_col in zip(*b)] for a_row in a]

def mx_unit(rank):
	return [[0] * i + [1] + (rank - i - 1) * [0] for i in range(rank)]

def mx_pow(mx, n, mo):
	rank = len(mx)
	ret = mx_unit(rank)
	while n:
		if n & 1:
			ret = mx_times(ret, mx, mo)
		n >>= 1
		mx = mx_times(mx, mx, mo)
	return ret

def mx_step(n, i):
	ret = mx_unit(n)
	ret[(i + 1) % n][i] = ret[(i - 1) % n][i] = 1
	return ret

def circle_summation(steps, vec):
	n = len(vec)
	init = [vec[-i:] + vec[:-i] for i in range(n, 0, -1)]
	if steps >= n:
		full = mx_unit(n)
		for i in range(n):
			full = mx_times(full, mx_step(n, i), modulo_constant)
		init = mx_times(init, mx_pow(full, steps // n, modulo_constant), modulo_constant)
		steps = steps % n
	for i in range(steps):
		init = mx_times(init, mx_step(n, i), modulo_constant)
	return [row[-i:] + row[:-i] for (i, row) in enumerate(init)]

def run_circle_summation(reader=input, printer=print):
	t = int(reader())
	for _ in range(t):
		(n, m) = [int(x) for x in reader().split()]
		vec = [int(x) for x in reader().split()]
		assert n == len(vec)
		for row in circle_summation(m, vec):
			printer(' '.join(map(str, row)))
		printer('')
run_circle_summation()


MOD = 1000000007

def mult(a, b):
	n = len(a)
	c = [[0] * n for i in range(n)]
	for i in range(n):
		for j in range(n):
			for k in range(n):
				c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % MOD
	return c

def exp(m, e):
	res = [[1 if i == j else 0 for j in range(len(m))] for i in range(len(m))]
	while e > 0:
		if e & 1:
			res = mult(res, m)
		m = mult(m, m)
		e >>= 1
	return res

def get_matrix(n, m):
	mat = [[0 for i in range(n)] for j in range(n)]
	for i in range(1, n):
		mat[i - 1][i] = 1
	mat[n - 1][0] = mat[n - 1][1] = mat[n - 1][n - 1] = 1
	return exp(mat, m)

def mult_vec(mat, vec):
	n = len(mat)
	res = [0 for i in range(n)]
	for i in range(n):
		for j in range(n):
			res[i] = (res[i] + mat[i][j] * vec[j]) % MOD
	return res
t = int(input())
for _ in range(t):
	(n, m) = map(int, input().split())
	a = list(map(int, input().split()))
	M = get_matrix(n, m)
	r = m % n
	for i in range(n):
		res = mult_vec(M, a)
		print(*res[-r:] + res[:-r])
		r = (r + 1) % n
		a = a[1:] + a[:1]
	if _ < t - 1:
		print()