import scala.math.{min,max}

object Main {
  val sc = new java.util.Scanner(System.in);
  def solve(s: String): String = {
    s.length match {
      case 0 => ""
      case 1 => s
      case _ => {
        val r = solve(s.drop(3))
        r.find(_ == s(0)) match {
          case Some(_) => r
          case None => {
            s(1) match {
              case '-' => s(0) + r
              case '<' => r + s(0)
              case _ => "error"
            }
          }
        }
      }
    }
  }
  def main(args: Array[String]) {
    val n = sc.nextInt
    for(i <- 1 to n) {
      val s = sc.next
      println(solve(s))
    }
  }
}