#include <iostream>
#include <vector>

using namespace std;
typedef vector<int> vec;
typedef vector<vec> mat;

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

mat mul(const mat &A, const mat &B) {
	mat C(A.size(), vec(B[0].size()));
	for (int i = 0; i < A.size(); i++)
		for (int k = 0; k < B.size(); k++)
			for (int j = 0; j < B[0].size(); j++)
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
	return C;
}

mat powMat(mat A, int n) {
	mat B(A.size(), vec(A.size()));
	for (int i = 0; i < A.size(); i++)
		B[i][i] = 1;
	while (n >> 0) {
		if (n & 1) B = mul(B, A);
		A = mul(A, A);
		n >>= 1;
	}
	return B;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (cin >> N >> M >> A >> B >> C >> T, N || M || A || B || C || T) {
		vec s(N);
		for (int i = 0; i < N; i++)
			cin >> s[i];

		mat a(N, vec(N));
		a[0][0] = B;	a[0][1] = C;
		a[N - 1][N - 2] = A; a[N - 1][N - 1] = B;
		for (int i = 1; i < N - 1; i++)
			a[i][i - 1] = A, a[i][i] = B, a[i][i + 1] = C;
		a = powMat(a, T);
		vec ans(N);
		for (int i = 0; i < N; i++)
			for (int j = 0; j < N; j++)
				ans[i] += a[i][j] * s[j];
		for (int i = 0; i < N - 1; i++)
			cout << ans[i] % M << " ";
		cout << ans[N - 1] % M << endl;
	}
}