def init(a, b, c, n)
  matrix = n.times.map{ [0] * n }
  matrix[0][0] = b
  matrix[0][1] = c
  matrix[n - 1][n - 2] = a
  matrix[n - 1][n - 1] = b
  (1..n - 2).each do |i|
    matrix[i][i - 1] = a
    matrix[i][i] = b
    matrix[i][i + 1] = c
  end
  matrix
end

def mul(mat1, mat2, n, m)
  ret = n.times.map{ [0] * n }
  n.times do |i|
    n.times do |j|
      n.times do |k|
        ret[i][k] += (mat1[i][j] * mat2[j][k]) % m
      end
    end
  end
  ret
end

def pow(matrix, n, m, t)
  unit = n.times.map{ [0] * n }
  n.times{ |i| unit[i][i] = 1 }
  while t > 0
    unit = mul(matrix, unit, n, m) if t & 1 == 1
    matrix = mul(matrix, matrix, n, m)
    t >>= 1
  end
  unit
end

loop do
  n, m, a, b, c, t = gets.split.map(&:to_i)
  break if n == 0
  mat = init(a, b, c, n)
  state = gets.split.map(&:to_i)
  ret = pow(mat, n, m, t)
  puts n.times.map{ |i| n.times.map{ |j| ret[i][j] * state[j] }.reduce(:+) % m } * ' '
end