#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
typedef vector<vector<int>> Graph;
typedef vector<vector<int>> Mat;
const int inf = 1e9;
const int mod = 1e9 + 7;

int N, M, A, B, C, T;

inline Mat mulMatMat(const Mat& a, const Mat& b) {
    int n = a.size();
    int m = b[0].size();
    assert(a[0].size() == b.size());
    Mat c(n, V(m, 0));
    rep(i, n) {
        rep(j, m) {
            rep(k, a[0].size()) {
                (c[i][j] += a[i][k] * b[k][j]) %= M;
            }
        }
    }
    return c;
}

inline V mulMatVec(const Mat& a, const V& v) {
    int n = a.size();
    assert(a[0].size() == v.size());
    V c(n, 0);
    rep(i, n) {
        rep(j, a[0].size()) {
            (c[i] += a[i][j] * v[j]) %= M;
        }
    }
    return c;
}

signed main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);

    while (cin >> N >> M >> A >> B >> C >> T, N) {
        V s(N + 2);
        rep2(i, 1, N + 1) cin >> s[i];

        VV a(N + 2, V(N + 2));
        rep2(i, 1, N + 1) {
            a[i][i - 1] = A,    a[i][i] = B,    a[i][i + 1] = C;
        }

        for (; T > 0; T >>= 1) {
            if (T & 1) {
                s = mulMatVec(a, s);
            }
            a = mulMatMat(a, a);
        }

        rep2(i, 1, N + 1) {
            cout << (i != 1 ? " " : "") << s[i];
        }
        cout << endl;

    }
}