DList = Struct.new :x, :p, :n
gets.to_i.times do
  initial, *xs = gets.scan(/[a-z]|->|<-/)
  l = DList.new initial
  xs.each_slice(2) do |c, x|
    if c == '<-'
      unless l.p
        l.p = DList.new x
        l.p.n = l
      end
      l = l.p
    else
      unless l.n
        l.n = DList.new x
        l.n.p = l
      end
      l = l.n
    end
  end
  l = l.p while l.p
  while l
    print l.x
    l = l.n
  end
  puts
end