#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vvi matrix;

int N,M,A,B,C,T;

void init(matrix &mat)
{

  mat[N-1][N-2]             = A;
  mat[0][0] = mat[N-1][N-1] = B;
  mat[0][1]                 = C;
  REP(i,1,N-1)
    {
      mat[i][i-1] = A;
      mat[i][i] = B;
      mat[i][i+1] = C;
    }
}

matrix identity(int n)
{
  matrix A(n,vector<int>(n));
  for(int i=0;i<n;i++) A[i][i] = 1;
  return A;
}

matrix multi(const matrix& A,const matrix& B)
{
  matrix C(A.size(),vector<int>(B[0].size()));
  for(int i=0;i<C.size();++i)
    for(int j=0;j<C[i].size();++j)
      for(int k=0;k<A[i].size();++k)
	C[i][j] = (C[i][j]+(A[i][k]*B[k][j])%M)%M;
  return C;
}

matrix pow(const matrix& A,int e)
{
  return !e?identity(A.size()):
    (e%2?multi(A,pow(A,e-1)):pow(multi(A,A),e/2));
}

void print(matrix &mat)
{
  cout << "^^^^^^^^^^" << endl;
  rep(i,mat.size())
    {
      rep(j,mat[i].size())
	{
	  cout << mat[i][j] << " ";
	}
      cout << endl;
    }
  cout << "-------------" << endl;
}

int main()
{
  while(cin >> N >> M >> A >> B >> C >> T,N|M|A|B|C|T)
    {
      matrix s(N,vi(1));
      rep(i,N)cin >> s[i][0];
      matrix coef(N,vi(N,0));
      init(coef);
      coef = pow(coef,T);
      s = multi(coef,s);
      rep(i,N)cout << (i?" ":"") << s[i][0];
      cout << endl;
    }
  return 0;
}