#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>
#include <cassert>
using namespace std;

//common
#define BR "\n"

#define ALL(c) (c).begin(),(c).end()
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define EACH(it,o) for(auto it = (o).begin(); it != (o).end(); ++it)
#define IN(l,v,r) ((l)<=(v) && (v)<(r))

typedef vector<int> vi; typedef pair<int,int> pii; typedef vector<pair<int,int> > vpii;
typedef long long ll; typedef vector<long long> vl; typedef pair<long long,long long> pll; typedef vector<pair<long long,long long> > vpll;
typedef vector<string> vs; typedef long double ld;

//config
#define MODE_DEBUG
//#define INF 1<<30
//#define EPS 1e-8
//const ll MOD =100000007;

//debug
#ifdef MODE_DEBUG
#define  DUMP(x)  cerr << #x << " = " << (x) <<endl
#define DEBUG(x) DUMP(x) << " (L" << __LINE__ << ")" << " " << __FILE__<<endl
#define CHECK(exp,act)  if(exp!=act){DUMP(exp);DEBUG(act);}
#define STOP(e)  CHECK(e,true);if(!(e)) exit(1);
#else
#define DUMP(x)
#define DEBUG(x)
#define CHECK(exp,act)
#define STOP(e)
#endif

#define H(mat) mat.size()
#define W(mat) mat[0].size()

template<class T> inline string toString(const vector<T>& x) {
	stringstream ss;
	REP(i,x.size()){
		if(i!=0)ss<<" ";
		ss<< x[i];
	}
	return ss.str();
}
template<class T> inline string toString(const vector<vector<T>>& map) {
	stringstream ss;
	REP(i,map.size()){
		if(i!=0)ss<<BR;
		ss<< toString(map[i]);
	}
	return ss.str();
}
template<class K,class V>  string toString(map<K,V>& x) {
	string res;stringstream ss;
	for(auto& p:x)ss<< p.first<<":" << p.second<<" ";
	return ss.str();
}

template<typename T,typename V> inline T mod(T v,V MOD){
	return (v%MOD+MOD)%MOD;
}



namespace Matrix{
	const ll MOD=10007;

	template <typename T=int> class Mat :public vector<vector<T>> {
		public:
		Mat(int H,int W,T v) : vector<vector<T>>(){
			this->_M_fill_assign(H,vector<T>(W,v));
		}
		Mat(int H,int W): vector<vector<T>>(){
			this->_M_fill_assign(H,vector<T>(W));
		}
		//O(n^2)
		Mat operator+(const Mat& r){
			auto& l=*this;
			if(H(r)!=H(l) || W(l)!=W(r)) DEBUG("error");
			Mat res(H(l),W(r));
			REP(y,H(l))REP(x,W(r)) res[y][x]=l[y][x]+r[y][x];
			return res;
		}
		//O(n^2)
		Mat operator-(const Mat<T>& r){
			auto& l=*this;
			if(H(r)!=H(l) || W(l)!=W(r))DEBUG("error");
			Mat<T> res(H(l),W(r));
			REP(y,H(l))REP(x,W(r)) res[y][x]=l[y][x]-r[y][x];
			return res;
		}
		//O(LH*N*RW) O(n^3)
		Mat operator*(const Mat<T>& r){
			auto& l=*this;
			if(W(l)!=H(r)) DEBUG("error");
			Mat<T> res(H(l),W(r));
			REP(y,H(l))REP(x,W(r))
				REP(k,H(r)) res[y][x]+=l[y][k]*r[k][x];
			return res;
		}
		//O(n^2)
		vector<T> operator*(const vector<T>& r){
			auto& l=*this;
			vector<T> res(r.size());
			REP(y,H(l))REP(x,W(l))res[y]+=l[y][x]*r[x];
			return res;
		}
		//O(n^2)
		Mat<T> operator%(ll MOD){
			auto& m =*this;
			Mat<T> res(H(m),W(m));
			REP(y,H(m))REP(x,W(m)) res[y][x]=mod(m[y][x],MOD);
			return res;
		}

		static Mat E(int n){
			return E(n,n);
		}
		static Mat E(int h,int w){
			Mat E(h,w);
			REP(i,min(h,w))E[i][i]=1;
			return E;
		}

		// O(size^3*log(n))
		// Mat x must be n*n size
		static Mat mod_pow(Mat& x,ll n,T MOD){
			Mat res=E(H(x),W(x));
			while(n!=0){
				if((n&1)==1)res=res*x%MOD;
				x=x*x%MOD;
				n>>=1;
			}
			return res;
		}
	};
}
using namespace Matrix;

int main(){
	while(true){
		int N,M,A,B,C,T;cin >> N >> M >> A >> B >> C >> T;
		if(N==0 && M==0)break;
		vector<int> bs(N);
		REP(i,N)cin >> bs[i];
		Mat<int> mat(N,N);
		REP(y,N)REP(x,N){
			if(x==y-1)mat[y][x]=A;
			if(x==y)mat[y][x]=B;
			if(x==y+1)mat[y][x]=C;
		}
		Mat<int> m=Mat<int>::mod_pow(mat,T,M);
		bs=m*bs;
		REP(i,bs.size())bs[i]=mod(bs[i],M);
		cout<< toString(bs)<<endl;
	}


	return 0;
}

Measured memory_bytes: 1292