import scala.io.StdIn.{readLine,readInt}
import scala.collection.mutable.ArrayBuffer

object Main {
  class Node(id:Int,dist:Int) { }

  def main(args:Array[String]) = {
    val n = readInt
    val b = new ArrayBuffer[String]
    for(i<-0 until n) {
      val l = readLine.trim
      var s = l(0).toString
      var j = 1
      while(j < l.length) {
        if(!s.contains(l(j+2))) {
          if(l(j+1) == '>') s = s+l(j+2) else s = l(j+2) + s
        }
        j = j+3
      }
      b += s
    }
    println(b.mkString("\n"))
  }
}