#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"
#include "ctime"

using namespace std;

constexpr long long int MOD = 1000000007;
//constexpr int MOD = 1000000007;
//constexpr int MOD = 998244353;
//constexpr long long int MOD = 998244353;
constexpr double EPS = 1e-12;

//int N, M, K, T, H, W, L, R;
long long int N, M, K, T, H, W, L, R;

vector<vector<long long int>>matrix_product(vector<vector<long long int>>v, vector<vector<long long int>>w) {
	vector<vector<long long int>>ret(v.size(), vector<long long int>(w.front().size()));
	for (int i = 0; i < ret.size(); i++) {
		for (int j = 0; j < ret[i].size(); j++) {
			for (int k = 0; k < w.size(); k++) {
				ret[i][j] += v[i][k] * w[k][j];
				ret[i][j] %= M;
			}
		}
	}
	return ret;
}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);

	int a, b, c;
	while (cin >> N >> M >> a >> b >> c >> T, N) {
		vector<int>v(N);
		for (auto &i : v)cin >> i;
		vector<vector<long long int>>by(N, vector<long long int>(N));
		for (int i = 0; i < N; i++)by[i][i] = 1;
		vector<vector<long long int>>box(N, vector<long long int>(N));
		for (int i = 0; i < N; i++) {
			if (i) {
				box[i][i - 1] = a;
			}
			box[i][i] = b;
			if (i + 1 < N)box[i][i + 1] = c;
		}
		for (int i = 0; i < 30; i++) {
			if ((T >> i) & 1) {
				by = matrix_product(box, by);
			}
			box = matrix_product(box, box);
		}
		vector<vector<long long int>>ans(N, vector<long long int>(1));
		for (int i = 0; i < N; i++) {
			ans[i][0] = v[i];
		}
		ans = matrix_product(by, ans);
		for (int i = 0; i < N; i++) {
			if (i)cout << " ";
			cout << ans[i][0];
		}
		cout << endl;
	}
}
