fun main(args: Array<String>?): Unit {
    while(true){
        val (n, m, a, b, c, t) = readLine()!!.trim().split(' ').map(String::toInt)
        if (n == 0) return
        val s = readLine()!!.trim().split(' ').map{it.toInt() % m}
        val matrix = Array(n){i -> IntArray(n){j -> if (i - 1 == j) a else if (i == j) b else if (i + 1 == j) c else 0}}
        println(
                times(matrix.exp(t, m), s.toIntArray(), m).joinToString(" ")
        )
    }
}
operator fun List<Int>.component6(): Int = this[5]

fun times(a: Array<IntArray>, b: Array<IntArray>, m: Int): Array<IntArray> {
    val result = Array(a.size){IntArray(b.first().size){0}}
    for (i in result.indices) {
        for (j in result[i].indices) {
            for (k in a[i].indices) {
                result[i][j] += a[i][k] * b[k][j]
            }
            result[i][j] %= m
        }
    }
    return result
}
fun times(a: Array<IntArray>, b: IntArray, m: Int): IntArray {
    return times(a, b.map{ intArrayOf(it)}.toTypedArray(), m).map{it.first()}.toIntArray()
}
fun double(a: Array<IntArray>, m: Int): Array<IntArray> {
    return times(a, a, m)
}
fun Array<IntArray>.exp(p: Int, m: Int): Array<IntArray> {
    return when(p){
        0 -> Array(this.size){i -> IntArray(this.size){j -> if (i == j) 1 else 0}}
        1 -> this
        else -> if (p % 2 == 0) double(this.exp(p / 2, m), m) else times(this, double(this.exp(p / 2, m), m), m)
    }
}
