
fun main(args:Array<String>):Unit {
    val (n, q) = readLine()!!.split(' ').map(String::toInt)
    val vectors = Array(n){Vector()}
    repeat(q){
        val query = readLine()!!.split(' ').map(String::toInt)
        when(query.first()){
            0 -> vectors[query[1]].pushBack(query.last())
            1 -> println(vectors[query.last()].dump())
            else -> vectors[query.last()].clear()
        }
    }
}

class Vector{
    private var mArray:Array<Int> = Array(100){0}
    var size:Int = 0
        private set
    private fun resize():Unit {
        val newArray = Array(mArray.size * 2){0}
        mArray.forEachIndexed { index, i -> newArray[index] = i }
        mArray = newArray
    }
    fun pushBack(value:Int):Unit {
        if (size == mArray.size) resize()
        mArray[size++] = value
    }
    fun clear():Unit {
        size = 0
    }
    fun dump():String {
        return (0 until size).map{mArray[it]}.joinToString(" ")
    }
}
