def mult(a,b,mod)
    c = Array.new(a.size).map{Array.new(b[0].size,0)}
    a.size.times do |i|
        b.size.times do |k|
            b[0].size.times do |j|
                c[i][j] = (c[i][j] + a[i][k] * b[k][j]) % mod;
            end
        end
    end
    c
end
def pow(a,n,mod)
    b = Array.new(a.size).map{Array.new(a.size,0)}
    a.size.times do |i|
        b[i][i] = 1
    end
    while n > 0
        b = mult(b,a,mod) if n & 1 > 0
        a = mult(a,a,mod)
        n >>= 1
    end
    b
end
loop do
    n, m, a, b, c, t = gets.split.map(&:to_i)
    break if n == 0
    s = [gets.split.map(&:to_i)].transpose
    arr = Array.new(n).map{Array.new(n,0)}
    n.times do |i|
        arr[i][i-1] = a if i > 0
        arr[i][i] = b
        arr[i][i+1] = c if i < n - 1
    end
    arr = pow(arr,t,m)
    arr = mult(arr,s,m)
    puts arr.flatten * " "
end