#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; double w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int M;

vector< vector<ll> > matmul(vector< vector<ll> >& A, vector< vector<ll> >& B) {
	int n = A.size();
	vector< vector<ll> > C(n, vector<ll>(n));
	for (int i = 0; i < n; i++)
		for (int j = 0; j < n; j++)
			for (int k = 0; k < n; k++)
				C[i][j] = (C[i][j] + A[i][k] * B[k][j]) % M;
	return C;
}

vector< vector<ll> > matpow(vector< vector<ll> > A, ll x) {
	int n = A.size();
	vector< vector<ll> > B(n, vector<ll>(n));
	for (int i = 0; i < n; i++) B[i][i] = 1;
	while (x > 0) {
		if (x % 2) B = matmul(B, A);
		x /= 2;
		A = matmul(A, A);
	}
	return B;
}

int main() {
	for (;;) {
		int N, A, B, C, T;
		cin >> N >> M >> A >> B >> C >> T;
		if (N == 0) break;
		vector< vector<ll> > a(N, vector<ll>(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;
		}
		a = matpow(a, T);
		vector<int> S(N);
		for (int i = 0; i < N; i++) cin >> S[i];
		for (int i = 0; i < N; i++) {
			int ans = 0;
			for (int j = 0; j < N; j++) 
				ans = (ans + a[i][j] * S[j]) % M;
			cout << ans << (i + 1 < N ? ' ' : '\n');
		}
	}
}