object Main extends App {
	var S = scala.io.StdIn.readLine.toList.map(_.toString)
	val q = scala.io.StdIn.readInt

	for(i<-0 until q){
		val a = scala.io.StdIn.readLine.split(" ")

		if(a(0).toInt == 1){
			S = S.reverse
		}else{
			if(a(1).toInt == 1) S = a(2) :: S
			else S = S :+ a(2)
		}
	}

	println(S.mkString)

}