def calc(state, n)
  ret = []
  state = [0] + state + [0]
  (1..n).each do |i|
    ret << (@a * state[i - 1] + @b * state[i] + @c * state[i + 1]) % @m
  end
  ret
end

def evolve(state, ss, n, t)
  ss[state] = 0
  (1..t).each do |i|
    state = calc(state, n)
    return (t - ss[state]) % (i - ss[state]) + ss[state] if ss.has_key?(state)
    ss[state] = i
  end
  t
end

loop do
  n, @m, @a, @b, @c, t = gets.split.map(&:to_i)
  break if n == 0
  ss = {}
  state = gets.split.map(&:to_i)
  if t == 0
    puts state * ' '
    next
  end
  tt = evolve(state, ss, n, t)
  puts ss.key(tt) * ' '
end