import scala.collection.mutable.ListBuffer
import scala.io.StdIn.readLine

object Main extends App {
  val pushBack = 0
  val dump     = 1
  val clear    = 2

  val Array(n, q) = readLine().split(" ").map { _.toInt }
  val lines       = Iterator.fill(q)(readLine())

  val orders = lines.map { _.split(" ").map { _.toInt } }

  val xss = Array.fill(n)(Vector.empty[Int])
  orders.foreach {
    case Array(`pushBack`, t, x) => xss(t) = xss(t) :+ x
    case Array(`dump`, t)        => println(xss(t).mkString(" "))
    case Array(`clear`, t)       => xss(t) = Vector.empty[Int]
  }
}

