object Main extends App {
  val s = scala.io.StdIn.readLine()
  val q = scala.io.StdIn.readInt()

  var result = s

  (1 to q).foreach { _ =>
    val query = scala.io.StdIn.readLine()
    if (query == "1") {
      result = (for(i <- result.length - 1 to 0 by -1) yield result(i)).mkString
    } else {
      val querySplit = query.split(" ")
      if (querySplit(1) == "1") {
        result = querySplit(2) + result
      } else {
        result = result + querySplit(2)
      }
    }
  }

  println(result)
}