import std.stdio;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;

class Matrix {
    int[][] v;
    size_t y, x;
    this(size_t y, size_t x) {
        this.y = y;
        this.x = x;
        this.v = new int[][](y, x);
    }
    this(int[][] v) {
        this.y = v.length;
        this.x = v[0].length;
        this.v = new int[][y];
        foreach (i; 0 .. y) {
            this.v[i] = v[i].dup;
        }
    }
    Matrix map(int function(int) f) {
        foreach (i; 0 .. y) {
            foreach (j; 0 .. x) {
                v[i][j] = f(v[i][j]);
            }
        }
        return this;
    }
    Matrix opBinary(string op)(Matrix m) if (op == "*") {
        if (x != m.y) throw new Error("?");
        Matrix ret = new Matrix(y, m.x);
        foreach (i; 0 .. y) {
            foreach (j; 0 .. m.x) {
                foreach (k; 0 .. x) {
                    ret.v[i][j] += v[i][k] * m.v[k][j];
                }
            }
        }
        return ret;
    }
    Matrix opBinary(string op)(int M) if (op == "%") {
        Matrix ret = new Matrix(v);
        foreach (i; 0 .. y) {
            foreach (j; 0 .. x) {
                ret.v[i][j] %= M;
            }
        }
        return ret;
    }
    Matrix identity() {
        Matrix ret = new Matrix(y, x);
        foreach (i; 0 .. y) {
            ret.v[i][i] = 1;
        }
        return ret;
    }
    Matrix transpose() {
        //"transpose".writeln;
        Matrix ret = new Matrix(x, y);
        foreach (i; 0 .. y) {
            foreach (j; 0 .. x) {
                ret.v[j][i] = v[i][j];
            }
        }
        return ret;
    }
    override string toString() {
        return v.map!(l => l.map!(to!string).join(" ")).join("\n");
    }

    static Matrix modPow(Matrix m, int t, int M) {
        //writeln("Matrix.modPow ", t);
        if (t == 0) return m.identity;
        if (m.v.length != m.v[0].length) throw new Error("?");
        if (t == 1) return m;
        if (t % 2 == 0) return modPow((m * m) % M, t / 2, M); 
        return (modPow((m * m) % M, t / 2, M) * m) % M;
    }
}

void main() {
    int N, M, A, B, C, T;
    while (readf("%d %d %d %d %d %d\n", &N, &M, &A, &B, &C, &T), N || M || A || B || C || T) {
        Matrix S = new Matrix([readln.chomp.split(" ").map!(to!int).array]);
        Matrix m = new Matrix(N, N);
        foreach (i; 0 .. N) {
            if (i - 1 >= 0) m.v[i][i - 1] = A;
            m.v[i][i] = B;
            if (i + 1 < N) m.v[i][i + 1] = C;
        }
        writeln((Matrix.modPow(m, T, M) * (S.transpose) % M).transpose);
    }
}