gets $q = "" puts $<.readlines.map(&:chomp).map(&:split).each {|(m, c)| $q = m == ?0 ? $q + c : c + $q} puts $q