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

	var reverse_flag = false

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

		if(a(0).toInt == 1){
			reverse_flag = !reverse_flag
		}else{

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

	if(reverse_flag) S = S.reverse

	println(S.mkString)

}