#include <bits/stdc++.h>

using namespace std;
using i64 = long long int;
using ui64 = unsigned long long int;
using vi = vector<int>;
using vvi = vector<vi>;

////////////////////////////////

vvi mul(vvi a, vvi b, int m){
    assert(a[0].size() == b.size());
    vvi c(a.size(), vi(b[0].size()));
    for(int i=0;i<(int)a.size();i++){
        for(int j=0;j<(int)b[0].size();j++){
            for(int k=0;k<(int)b.size();k++){
                c[i][j] += a[i][k] * b[k][j];
                c[i][j] %= m;
            }
        }
    }
    return c;
}

void E(vvi &a){
    a.assign(a.size(), vi(a[0].size(), 0));
    for(int i=0;i<(int)a.size();i++)a[i][i] = 1;
}

vvi rp(const vvi &a, int n, const int &m){
    vvi r(a.size(), vi(a.size()));
    if(!n){
        E(r);
        return r;
    }
    r = rp(a, n >> 1, m);
    r = mul(r, r, m);
    if(n&1){
        return mul(a, r, m);
    }
    return r;
}

int main(){
    int n, m, a, b, c, t;
    while(cin >> n >> m >> a >> b >> c >> t, n|m|a|b|c|t){
        vvi d(n, vi(n, 0));
        for(int i=1;i<n-1;i++){
            d[i][i-1] = a;
            d[i][i] = b;
            d[i][i+1] = c;
        }
        d[0][0] = b;d[0][1] = c;d[n-1][n-2] = a;d[n-1][n-1] = b;
        
        vi e(n);
        for(auto&& x:e)cin >> x;
        vvi A = rp(d, t, m);
        
        vi ret(n, 0);
        for(int i=0; i<n; i++)
            for(int j=0;j<n;j++){
                ret[i] += A[i][j] * e[j];
                ret[i] %= m;
            }
        for(int i=0;i<n;i++)cout << ret[i] << (i==n-1 ? "\n" : " ");
    }
}
