output_description: For each dataset, output a line that contains the states of the cells at time
  _T_. The format of the output is as follows.
  
  _S_(0, _T_) _S_(1, _T_) ... _S_(_N_ − 1, _T_)
  
  Each state must be represented as an integer and the integers must be
  separated by a space.
input_description: The input is a sequence of datasets. Each dataset is formatted as follows.
  
  _N M A B C T_  
  _S_(0, 0) _S_(1, 0) ... _S_(_N_ − 1, 0)  
  
  The first line of a dataset consists of six integers, namely _N_ , _M_ , _A_ ,
  _B_ , _C_ and _T_. _N_ is the number of cells. _M_ is the modulus in the
  equation (1). _A_ , _B_ and _C_ are coefficients in the equation (1). Finally,
  _T_ is the time for which you should compute the states.
  
  You may assume that 0 < _N_ ≤ 50, 0 < _M_ ≤ 1000, 0 ≤ _A_ , _B_ , _C_ < _M_
  and 0 ≤ _T_ ≤ 109.
  
  The second line consists of _N_ integers, each of which is non-negative and
  less than _M_. They represent the states of the cells at time zero.
  
  A line containing six zeros indicates the end of the input.
attempt: # ittan copy & paste
  
  
  def mul(A, B, N, M):
      result = [[0] * N for i in range(N)]
      for i in range(N):
          for j in range(N):
              tmp = 0
              for k in range(N):
                  tmp += A[i][k] * B[k][j]
                  tmp %= M
              result[i][j] = tmp
      return result
  
  
  while 1:
      N, M, A, B, C, T = map(int, input().split())
      if N == 0:
          break
      (*S,) = map(int, input().split())
      P = [[0] * N for i in range(N)]
      for i in range(N):
          P[i][i] = B
      for i in range(N - 1):
          P[i + 1][i] = A
          P[i][i + 1] = C
      base = [[0] * N for i in range(N)]
      for i in range(N):
          base[i][i] = 1
      while T:
          if T & 1:
              base = mul(base, P, N, M)
          P = mul(P, P, N, M)
          T >>= 1
      U = [0] * N
      for i in range(N):
          tmp = 0
          for j in range(N):
              tmp += base[i][j] * S[j]
              tmp %= M
          U[i] = tmp
      print(*U)
  
problem_description: C: One-Dimensional Cellular Automaton
  
  There is a one-dimensional cellular automaton consisting of _N_ cells. Cells
  are numbered from 0 to _N_ − 1\.
  
  Each cell has a state represented as a non-negative integer less than _M_. The
  states of cells evolve through discrete time steps. We denote the state of the
  i-th cell at time t as _S_(_i_ , _t_). The state at time _t_ \+ 1 is defined
  by the equation
  
  _S_(_i_ , _t_ \+ 1) = (_A_ × _S_(_i_ − 1, _t_) + _B_ × _S_(_i_ , _t_) + _C_ ×
  _S_(_i_ \+ 1, _t_)) mod _M_ ,         (1)
  
  where _A_ , _B_ and _C_ are non-negative integer constants. For _i_ < 0 or _N_
  ≤ _i_ , we define _S_(_i_ , _t_) = 0.
  
  Given an automaton definition and initial states of cells, your mission is to
  write a program that computes the states of the cells at a specified time _T_.
samples: [{"input": "4 1 3 2 0\n    0 1 2 0 1\n    5 7 1 3 2 1\n    0 1 2 0 1\n    5 13 1 3 2 11\n    0 1 2 0 1\n    5 5 2 0 1 100\n    0 1 2 0 1\n    6 6 0 2 3 1000\n    0 1 2 0 1 4\n    20 1000 0 2 3 1000000000\n    0 1 2 0 1 0 1 2 0 1 0 1 2 0 1 0 1 2 0 1\n    30 2 1 0 1 1000000000\n    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n    30 2 1 1 1 1000000000\n    1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0\n    30 5 2 3 1 1000000000\n    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n    0 0 0 0 0 0", "output": "1 2 0 1\n    2 0 0 4 3\n    2 12 10 9 11\n    3 0 4 2 1\n    0 4 2 0 4 4\n    0 376 752 0 376 0 376 752 0 376 0 376 752 0 376 0 376 752 0 376\n    1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\n    1 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0\n    1 1 3 2 2 2 3 3 1 4 3 1 2 3 0 4 3 3 0 4 2 2 2 2 1 1 2 1 3 0"}]