#include <iostream>
#include <algorithm>

using namespace std;

const int N = 50;

void mult(int m1[N][N], int m2[N][N], int n, int m){
  int res[N][N];
  fill(res[0], res[N], 0);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int k=0;k<n;k++) res[i][j] = (res[i][j] + m1[i][k] * m2[k][j]) % m;
    }
  }
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) m1[i][j] = res[i][j];
}

void mod_pow(int mat[N][N], int p, int n, int m){
  int res[N][N];
  fill(res[0], res[N], 0);
  for(int i=0;i<n;i++) res[i][i] = 1;
  while(p > 0){
    if(p & 1) mult(res, mat, n, m);
    mult(mat, mat, n, m);
    p >>= 1;
  }
  for(int i=0;i<n;i++) for(int j=0;j<n;j++) mat[i][j] = res[i][j];
}

int main(){
  int n, m, a, b ,c, t, s[N], mat[N][N];
  while(cin >> n >> m >> a >> b >> c >> t && (n|m|a|b|c|t)){
    for(int i=0;i<n;i++) cin >> s[i];
    fill(mat[0], mat[N], 0);
    for(int i=0;i<n;i++){
      if(i - 1 >= 0) mat[i][i-1] = a;
      mat[i][i] = b;
      if(i + 1 < n) mat[i][i+1] = c;
    }
    mod_pow(mat, t, n, m);
    for(int i=0;i<n;i++){
      int ans = 0;
      for(int j=0;j<n;j++) ans = (ans + mat[i][j] * s[j]) % m;
      if(i) cout << " ";
      cout << ans;
    }
    cout << endl;
  }
}