N = gets.to_i keys = N.times.map { gets.chomp.split } ans = [] keys.each do |s, ch| if s == '0' ans.push(ch) else ans.unshift(ch) end end puts ans.join