puts gets.to_i.times.reduce(''){|s,e|f,c=gets.chomp.split;f=='0' ? s+c : c+s}