#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <cassert>
using namespace std;
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
const double EPS = 1e-9;
const double PI  = acos(-1.0);

vvi mul(vvi &m,vvi &n,int mod){
	int sz=m.size();
	vvi ret(sz,vi(sz));
	REP(i,sz){
		REP(j,sz){
			REP(k,sz){
				ret[i][j]+=m[i][k]*n[k][j];
				ret[i][j]=ret[i][j]%mod;
			}
		}
	}
	return ret;
}
vvi pow(vvi m,int t,int mod){
	int sz=m.size();
	vvi ret(sz,vi(sz,0));
	REP(i,sz){
		ret[i][i]=1;
	}
	while(t){
		if(t&1){
			ret=mul(ret,m,mod);
		}
		m=mul(m,m,mod);
		t>>=1;
	}
	return ret;
}
int main(){
	int n,m,a,b,c,t;
	while(cin>>n>>m>>a>>b>>c>>t,n|m|a|b|c|t){
		vi s(n);
		REP(i,n){
			cin>>s[i];
		}
		vvi matrix(n,vi(n));
		REP(i,n){
			FOR(j,i-1,i+1+1){
				if(j>=0&&j<n){
					int abc[3]={a,b,c};
					matrix[i][j]=abc[j-(i-1)];
				}
			}
		}
		vvi powed_matrix=pow(matrix,t,m);
		vvi ans(n,vi(n,0));
		REP(i,n){
			ans[i][0]=s[i];
		}
		ans=mul(powed_matrix,ans,m);
		REP(i,n){
			cout<<(i!=0?" ":"")<<ans[i][0];
		}
		cout<<endl;
	}
}