require 'matrix'

def exp(n, k, mod = nil)
	x = 1	
	r = n
	while k > 0
		x *= r if k & 1 == 1
		r *= r		
		if mod
			x %= mod
			r %= mod
		end
		k >>= 1
	end
	x
end

class Matrix
	def %(mod)
		map{|x| x % mod}
	end
end

loop {
	n, m, a, b, c, t = gets.split.map &:to_i 
	break if n == 0
	states = Vector[*gets.split.map(&:to_i)]
	mat = Matrix.build(n, n){|i, j|
		j == i-1 ? a :
		j == i   ? b :
		j == i+1 ? c : 0
	}
	puts (exp(mat, t, m) * states).to_a.map{|x| x % m}.join(" ")
}