#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;

int MOD = 10000;
struct mint { int n; mint(int n = 0) : n(n) { } };
mint operator+(mint a, mint b) { return (a.n += b.n) >= MOD ? a.n - MOD : a.n; }
mint operator-(mint a, mint b) { return (a.n -= b.n) < 0 ? a.n + MOD : a.n; }
mint operator*(mint a, mint b) { return 1LL * a.n * b.n % MOD; }
bool operator!=(mint a, mint b) { return a.n != b.n; }
mint &operator+=(mint &a, mint b) { return a = a + b; }
mint &operator-=(mint &a, mint b) { return a = a - b; }
mint &operator*=(mint &a, mint b) { return a = a * b; }
ostream &operator<<(ostream &os, mint a) { return os << a.n; }
istream &operator>>(istream &is, mint& a) { return is >> a.n; }

template<class T> ostream& operator<< (ostream& os, vector<T>& vec) {
    for (int i = 0; i < vec.size(); ++i) os << vec[i] << " "; return os;
}
template<class T> struct Matrix {
    vector<vector<T> > val;
    Matrix(int n = 1, int m = 1, T x = 0) { val.assign(n, vector<T>(m, x)); }
    size_t size() const { return val.size(); }
    vector<T>& operator[] (int i) { return val[i]; }
    const vector<T>& operator[] (int i) const { return val[i]; }
    friend ostream& operator<< (ostream& os, const Matrix<T> M) {
        for (int i = 0; i < M.size(); ++i) os << M[i] << "\n "[i == M.size() - 1];
        return os;
    }
};
template<class T> Matrix<T> operator* (const Matrix<T>& A, const Matrix<T>& B) {
    Matrix<T> R(A.size(), B[0].size());
    for (int i = 0; i < A.size(); ++i) for (int j = 0; j < B[0].size(); ++j)
        for (int k = 0; k < B.size(); ++k) R[i][j] += A[i][k] * B[k][j];
    return R;
}
template<class T> Matrix<T> operator^ (Matrix<T> &A, long long n) {
    Matrix<T> R(A.size(), A.size());
    for (int i = 0; i < A.size(); ++i) R[i][i] = 1;
    while (n > 0) { if (n & 1) R = R * A; A = A * A; n >>= 1; }
    return R;
}
template<class T> vector<T> operator* (const Matrix<T> &A, vector<T> &B) {
    vector<T> v(A.size());
    for (int i = 0; i < A.size(); ++i)
        for (int k = 0; k < B.size(); ++k) v[i] += A[i][k] * B[k];
    return v;
}
template<class T> Matrix<T> operator+ (const Matrix<T> &A, const Matrix<T> &B) {
    Matrix<T> R(A.size(), A[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < A[0].size(); ++j) R[i][j] = A[i][j] + B[i][j];
    return R;
}
template<class T> Matrix<T> operator- (const Matrix<T> &A, const Matrix<T> &B) {
    Matrix<T> R(A.size(), A[0].size());
    for (int i = 0; i < A.size(); ++i)
        for (int j = 0; j < A[0].size(); ++j) R[i][j] = A[i][j] - B[i][j];
    return R;
}

int main() {
    // S(i, t + 1) = (A × S(i − 1, t) + B × S(i, t) + C × S(i + 1, t)) mod M
    int n, m, a, b, c, t;
    while (cin >> n >> m >> a >> b >> c >> t, n) {
        MOD = m;
        vector<mint> B(n);
        for (mint& state : B) cin >> state;
        Matrix<mint> A(n, n);
        for (int i = 0; i < n; i++) {
            if (i - 1 >= 0) A[i][i - 1] = a;
            A[i][i] = b;
            if (i + 1 < n) A[i][i + 1] = c;
        }
        vector<mint> R = (A ^ t) * B;
        for (int i = 0; i < n; i++) {
            cout << R[i] << " \n"[i == n - 1];
        }
    }
    return 0;
}


Measured memory_bytes: 3120