#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif
template<class T> ostream& operator<<(ostream& os, vector<T> const& v){
    rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" ");
    return os;
}

int N,M,A,B,C,T;
int S[55];

int & mod = M;

struct mint{
    ll x;
    mint(ll x = 0) : x(x) {
        if(x < 0){
            // choose
            // x = abs(x);
            x = mod - abs(x)%mod;
        }
        x %= mod;
    }
    mint & operator += (mint const & v) { if((x += v.x) >= mod) x -= mod; return *this;}
    mint & operator -= (mint const & v) { if((x += mod-v.x) >= mod) x -= mod; return *this;}
    mint & operator *= (mint const & v) { x = 1LL*x*v.x % mod; return *this;}
    mint & operator /= (mint const & v) {
        // choose
        // x *= inv[x]
        x = 1LL*x*v.exp(mod-2).x % mod;
        return *this;
    }
    mint operator + (mint const & v)const{ return mint(*this) += v;}
    mint operator - (mint const & v) const { return mint(*this) -= v;}
    mint operator * (mint const & v) const { return mint(*this) *= v;}
    mint operator / (mint const & v) const { return mint(*this) /= v;}
    bool operator < (mint const & v) const { return x < v.x;}
    bool operator > (mint const & v) const { return x > v.x;}
    bool operator == (mint const & v) const { return x < v.x || x > v.x; }
    bool operator <= (mint const & v) const { return !(x > v.x); }
    bool operator >= (mint const & v) const { return !(x < v.x); }
    mint exp(mint const & m) const { return exp(m.x); }
    // not verified
    mint exp(ll t) const {
        if(!t) return 1;
        bool sign = 0;
        if(t < 0){ sign = true; t *= -1; }
        mint e = *this, res = 1;
        for(; t; e*=e, t>>=1) if(t&1) res *= e;
        return sign ? mint(1)/res : res;
    }
};

#define MCR mat const&
template<typename T>
struct mat {
    vector<vector<T>> dat;
    int height, width;
    mat(int height = 0, int width = 0): dat(height, vector<T>(width)), height(height), width(width){}
    vector<T> const & operator [] (int i) const { return dat[i]; };
    vector<T> & operator [] (int i){ return dat[i]; };
    mat & operator += (MCR v){ rep(i,height) rep(j,width) dat[i][j]+=v[i][j]; return *this; }
    mat & operator -= (MCR v){ rep(i,height) rep(j,width) dat[i][j]-=v[i][j]; return *this; }
    mat & operator *= (MCR b){
        mat res(height, b.width);
        rep(i,height) rep(k,b.height) rep(j,b.width) res[i][j] += dat[i][k]*b[k][j];
        return *this = res;
    }
    mat operator + (MCR v) const { return mat(*this) += v; }
    mat operator - (MCR v) const { return mat(*this) -= v; }
    mat operator * (MCR v) const { return mat(*this) *= v; }
    bool operator < (MCR v) const { return dat < v.dat; }
    mat exp(ll t) const { int n = height; mat e = *this, res = id(n); for(; t; e*=e, t>>=1) if(t&1) res *= e; return res; }
    mat trans() const { mat t(width, height); rep(i,width) rep(j,height) t[i][j] = dat[j][i]; return t; }
    static mat id (int n) {
        mat res(n,n);
        rep(i,n) res[i][i] = 1;
        return res;
    }
};

typedef mat<mint> matrix;

int main(){
#ifdef LOCAL
    freopen("in","r", stdin);
#endif
    while(cin>>N>>M>>A>>B>>C>>T && N){
        matrix a(N,N), x(N,1);
        rep(i,N){
            int t; cin >> t;
            x[i][0] = t;
        }
        rep(i,N){
            if(i!=0) a[i][i-1] = A;
            a[i][i] = B;
            if(i!=N-1) a[i][i+1] = C;
        }
        vi ans(N);
        auto t = (a.exp(T)*x).trans();
        rep(i,N) ans[i] = t[0][i].x;
        cout << ans << endl;
    }
}

Measured memory_bytes: 1300