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

namespace detail {

bool is_zero(double d) {
    return (std::abs(d) < 1e-9);
}
bool is_zero(long double d) {
    return (std::abs(d) < 1e-9);
}

}

template <typename T>
class matrix {
public:
    matrix() = delete;
    matrix(int r, int c) 
        : v_(r, std::vector<T>(c)),
          row_(r),
          column_(c)
    {}
    matrix(std::vector<std::vector<T>> const& v)
        : v_(v),
          row_(v.size()),
          column_((v.size() == 0 ? 0 : v[0].size()))
    {}
    matrix(matrix const&) = default;
    matrix(matrix&&) = default;
    matrix& operator=(matrix const&) = default;
    matrix& operator=(matrix&&) = default;
    ~matrix() = default;

    std::vector<T>& operator[](unsigned int i) {
        return v_[i];
    }
    const std::vector<T>& operator[](unsigned int i) const {
        return v_[i];
    }
    matrix& operator+=(matrix const& other) {
        assert("matrix operator+: row or column size does not match" && other.row_size() == row_ && other.column_size() == column_);

        for(int i=0; i<row_; ++i) {
            for(int j=0; j<column_; ++j) {
                v_[i][j] += other[i][j];
            }
        }
        return *this;
    }
    matrix& operator-=(matrix const& other) {
        assert("matrix operator-: row or column size does not match" && other.row_size() == row_ && other.column_size() == column_);

        for(int i=0; i<row_; ++i) {
            for(int j=0; j<column_; ++j) {
                v_[i][j] -= other[i][j];
            }
        }
        return *this;
    }

    bool operator==(matrix const& rhs) const {
        if(row_ != rhs.row_size() || column_ != rhs.column_size()) {
            return false;
        }
        for(int i=0; i<row_; ++i) {
            for(int j=0; j<column_; ++j) {
                if(std::abs(v_[i][j] - rhs[i][j]) > 1e-9) {
                    return false;
                }
            }
        }
        return true;
    }
    bool operator!=(matrix const& rhs) {
        return !(*this == rhs);
    }

    int row_size() const {
        return row_;
    }
    int column_size() const {
        return column_;
    }

    // for debug
    void print() {
        for(int i=0; i<row_; ++i) {
            for(int j=0; j<column_; ++j) {
                std::cout << v_[i][j];
                if(j != column_ - 1) {
                    std::cout << " ";
                }
            }
            std::cout << std::endl;
        }
    }

private:
    std::vector<std::vector<T>> v_;
    int row_, column_;
};

template <typename T>
matrix<T> operator-(matrix<T> m) {
    for(int i=0; i<m.row_size(); ++i) {
        for(int j=0; j<m.column_size(); ++j) {
            m[i][j] = -m[i][j];
        }
    }
}

template <typename T>
matrix<T> operator+(matrix<T> lhs, matrix<T> const& rhs) {
    lhs += rhs;
    return lhs;
}

template <typename T>
matrix<T> operator-(matrix<T> lhs, matrix<T> const& rhs) {
    lhs -= rhs;
    return lhs;
}

template <typename T>
matrix <T> operator*(matrix<T> const& lhs, matrix<T> const& rhs) {
    assert("matrix operator*: lhs.column_size() != rhs.row_size()" && lhs.column_size() == rhs.row_size());

    matrix<T> ret(lhs.row_size(), rhs.column_size());
    for(int i=0; i<ret.row_size(); ++i) {
        for(int k=0; k<lhs.column_size(); ++k) {
            for(int j=0; j<ret.column_size(); ++j) {
                ret[i][j] += lhs[i][k] * rhs[k][j];
            }
        }
    }
    return ret;
}

template <typename T>
matrix<T> eye(int n) {
    matrix<T> res(n, n);
    for(int i=0; i<n; ++i) {
        res[i][i] = 1;
    }
    return res;
}

template <typename T>
matrix<T> mul(matrix<T> const& a, matrix<T> const& b, const int M) {
    int R = a.row_size(), C = b.column_size();
    assert("matrix mul: row and column size does not match" && a.column_size() == b.row_size());
    matrix<T> ret(R, C);
    for(int i=0; i<R; ++i) {
        for(int k=0; k<a.column_size(); ++k) {
            for(int j=0; j<C; ++j) {
                ret[i][j] = (ret[i][j] + a[i][k] * b[k][j]) % M;
            }
        }
    }
    return ret;
}

template <typename T>
matrix<T> pow(matrix<T> x, long long y, const int M) {
    assert("matrix pow: matrix is not square" && x.column_size() == x.row_size());
    matrix<T> ret = eye<T>(x.column_size());
    while(y > 0) {
        if(y & 1) {
            ret = mul(ret, x, M);
        }
        x = mul(x, x, M);
        y >>= 1;
    }
    return ret;
}



int main() {
    int N, M, A, B, C, T;
    while(cin >> N >> M >> A >> B >> C >> T, N) {
        matrix<int> S(N, 1);
        for(int i=0; i<N; ++i) {
            cin >> S[i][0];
        }
        matrix<int> s(N, N);
        std::array<int, 3> c = {A, B, C};
        for(int i=0; i<N; ++i) {
            for(int j=-1; j<=1; ++j) {
                if(i+j < 0 || N <= i+j) {
                    continue;
                }
                s[i][i+j] = c[j+1];
            }
        }
        s = pow(s, T, M);
        auto res = mul(s, S, M);
        for(int i=0; i<N; ++i) {
            cout << res[i][0];
            if(i != N-1) {
                cout << " ";
            }
        }
        cout << endl;
    }
}


Measured memory_bytes: 3136