#include <bits/stdc++.h>
using namespace std;
using ll = long long;

unsigned int Mod;

struct mod_int {
	unsigned x;
	mod_int() : x(0) { }
	mod_int(int sig) { int sigt = sig % Mod; if (sigt < 0) sigt += Mod; x = sigt; }
	mod_int(long long sig) { int sigt = sig % Mod; if (sigt < 0) sigt += Mod; x = sigt; }
	int get() const { return (int)x; }

	mod_int &operator+=(mod_int that) { if ((x += that.x) >= Mod) x -= Mod; return *this; }
	mod_int &operator-=(mod_int that) { if ((x += Mod - that.x) >= Mod) x -= Mod; return *this; }
	mod_int &operator*=(mod_int that) { x = (unsigned long long)x * that.x % Mod; return *this; }
	mod_int &operator/=(mod_int that) { return *this *= that.inverse(); }

	mod_int operator+(mod_int that) const { return mod_int(*this) += that; }
	mod_int operator-(mod_int that) const { return mod_int(*this) -= that; }
	mod_int operator*(mod_int that) const { return mod_int(*this) *= that; }
	mod_int operator/(mod_int that) const { return mod_int(*this) /= that; }

	mod_int inverse() const {
		long long a = x, b = Mod, u = 1, v = 0;
		while (b) {
			long long t = a / b;
			a -= t * b; swap(a, b);
			u -= t * v; swap(u, v);
		}
		return mod_int(u);
	}
};

istream& operator >> (istream& is, mod_int& val) {
	long long x;
	is >> x; val = x;
	return is;
}

ostream& operator << (ostream& os, const mod_int& val) {
	os << val.get();
	return os;
}

using mint = mod_int;

template<class T>
class matrix {
	vector<vector<T>> dat;
public:
	matrix(int row) : dat(row, vector<T>(1)) {}
	matrix(int row, int col) : dat(row, vector<T>(col)) {}
	matrix(int row, int col, const T& id) : dat(row, vector<T>(col, id)) {}
	matrix(const vector<vector<T>>& v) : dat(v) {}
	matrix(const vector<T>& v) : dat(v.size(), vector<T>(1)) {
		for (int i = 0; i < (int)v.size(); ++i) dat[i][0] = v[i];
	}
	explicit operator vector<vector<T>>() const { return dat; }
	size_t get_row() const { return dat.size(); }
	size_t get_col() const { return dat[0].size(); }
	matrix<T>& operator+=(const matrix<T>& that) {
		int row = get_row(), col = get_col();
		assert(get_row() == that.get_row()  && get_col() == that.get_col());
		for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] += that[i][j];
		return *this;
	}
	matrix<T>& operator-=(const matrix<T>& that) {
		int row = get_row(), col = get_col();
		assert(get_row() == that.get_row() && get_col() == that.get_col());
		for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] -= that[i][j];
		return *this;
	}
	matrix<T>& operator*=(const T& that) {
		int row = get_row(), col = get_col();
		for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] *= that;
		return *this;
	}
	matrix<T>& operator/=(const T& that) {
		int row = get_row(), col = get_col();
		for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) dat[i][j] /= that;
		return *this;
	}
	matrix<T> operator*(const matrix<T>& that) const {
		int x = get_row(), y = get_col(), z = that.get_col();
		assert(get_col() == that.get_row());
		matrix<T> res(x, z);
		for (int i = 0; i < x; ++i) {
			for (int j = 0; j < y; ++j) {
				for (int k = 0; k < z; ++k) {
					res[i][k] += dat[i][j] * that[j][k];
				}
			}
		}
		return res;
	}
	matrix<T>& operator*=(const matrix<T>& that) { return *this = *this * that; }

	vector<T>& operator[](size_t i) & { return dat[i]; }
	const vector<T>& operator[](size_t i) const& { return dat[i]; }
	vector<T> operator[](size_t i) const&& { return move(dat[i]); }

	T& get(size_t i, size_t j) & {
		assert(0 <= i && i < get_row());
		assert(0 <= j && j < get_col());
		return dat[i][j];
	}
	const T& get(size_t i, size_t j) const& {
		assert(0 <= i && i < get_row());
		assert(0 <= j && j < get_col());
		return dat[i][j];
	}
	T get(size_t i, size_t j) const&& {
		assert(0 <= i && i < get_row());
		assert(0 <= j && j < get_col());
		return move(dat[i][j]);
	}
	void transpose() {
		int row = get_row(), col = get_col();
		vector<vector<T>> res(col, vector<T>(row));
		for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) res[j][i] = dat[i][j];
		dat = res;
	}
	matrix<T> get_transpose() const {
		int row = get_row(), col = get_col();
		matrix<T> res(col, row);
		for (int i = 0; i < row; ++i) for (int j = 0; j < col; ++j) res[j][i] = dat[i][j];
		return res;
	}
};

template <class T> matrix<T> operator+(const matrix<T>& a, const matrix<T>& b) { return matrix<T>(a) += b; }
template <class T> matrix<T> operator-(const matrix<T>& a, const matrix<T>& b) { return matrix<T>(a) -= b; }
template <class T> matrix<T> operator*(const matrix<T>& a, const T& b) { return matrix<T>(a) *= b; }
template <class T> matrix<T> operator*(const T& a, const matrix<T>& b) { return matrix<T>(b) *= a; }
template <class T> matrix<T> operator/(const matrix<T>& a, const T& b) { return matrix<T>(a) /= b; }

template <class T> matrix<T> zero_matrix(int n) { return matrix<T>(n, n); }

template <class T> matrix<T> identity_matrix(int n) {
	matrix<T> a(n, n);
	for (int i = 0; i < n; i++) a[i][i] = T(1);
	return a;
}

template <class T> matrix<T> pow(const matrix<T>& a, unsigned long long b) {
	int n = a.get_row();
	assert(a.get_row() == a.get_col());
	matrix<T> res = identity_matrix<T>(n), x(a);
	while (true) {
		if (b & 1ULL) res *= x;
		if (!(b >>= 1ULL)) break;
		x *= x;
	}
	return res;
}

int main()
{
	ios::sync_with_stdio(false), cin.tie(0);
	ll N, M, A, B, C, T;
	while (cin >> N >> M >> A >> B >> C >> T, N | M | A | B | C | T) {
		Mod = M;
		matrix<mint> mat(N, N);
		for (int i = 0; i < N; i++) {
			if (0 <= i - 1) mat[i][i - 1] = A;
			mat[i][i] = B;
			if (i + 1 < N) mat[i][i + 1] = C;
		}
		matrix<mint> b(N, 1);
		for (int i = 0; i < N; i++) {
			cin >> b[i][0];
		}
		auto&& res = pow(mat, T) * b;
		for (int i = 0; i < N; i++) {
			cout << res[i][0] << " \n"[i + 1 == N];
		}
	}
	return 0;
}



Measured memory_bytes: 3208