gets.to_i.times do
    h = {}
    a = gets.scan(/\w|->|<-/)
    h[0] = a.shift
    i = 0
    a.each_slice(2) do |dir, c|
        i += (dir == "->" ? 1 : -1)
        h[i] = c
    end
    puts h.sort.map(&:last).join
end