#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)

vector<vector<int>> multi(vector<vector<int>> m1, vector<vector<int>> m2,int M)
{
	vector<vector<int>> ans(m1.size(), vector<int>(m2[0].size(), 0));

	rep(i, m1.size()) {
		rep(j, m2[0].size()) {
			rep(k, m1[0].size()) {
				ans[i][j] += m1[i][k] * m2[k][j];
			}

			ans[i][j] %= M;
		}
	}

	return ans;
}

vector<vector<int>> mypow(vector<vector<int>> matrix, int n, int M)
{
	if (n == 0) {
		vector<vector<int>> I(matrix.size(), vector<int>(matrix.size(), 0));

		rep(i, matrix.size()) {
			I[i][i] = 1;
		}

		return I;
	}
	else if (n % 2 == 0) {
		return mypow(multi(matrix, matrix, M), n / 2, M);
	}
	else {
		return multi(mypow(multi(matrix, matrix, M), n / 2, M), matrix, M);
	}
}

int main()
{
	while (true) {
		int N, M, A, B, C, T;

		cin >> N >> M >> A >> B >> C >> T;

		if (N == 0 && M == 0 && A == 0 && B == 0 && C == 0 && T == 0) {
			break;
		}

		vector<int> t_zero(N);

		rep(i, N) {
			cin >> t_zero[i];
		}

		if (T == 0) {
			rep(i, N) {
				cout << t_zero[i];

				if (i == N - 1) {
					cout << endl;
				}
				else {
					cout << " ";
				}
			}

			continue;
		}

		vector<vector<int>> matrix(N, vector<int>(N, 0));

		rep(i, N) {
			if (i - 1 >= 0) {
				matrix[i][i - 1] = A;
			}

			matrix[i][i] = B;

			if (i + 1 < N) {
				matrix[i][i + 1] = C;
			}
		}

		matrix = mypow(matrix, T, M);

		vector<int> ans(N, 0);

		rep(i, N) {
			rep(j, N) {
				ans[i] += matrix[i][j] * t_zero[j];
			}

			ans[i] %= M;
		}

		rep(i, N) {
			cout << ans[i];

			if (i == N - 1) {
				cout << endl;
			}
			else {
				cout << " ";
			}
		}
	}


	return 0;
}