defmodule Main do def main do 1..(IO.read(:line) |> String.trim() |> String.to_integer()) |> Enum.map(fn _ -> IO.read(:line) |> String.trim() |> String.split() end) |> solve_rec([], []) |> IO.puts() end def solve_rec([], l, r) do (l |> Enum.join()) <> (r |> Enum.join() |> String.reverse()) end def solve_rec([[t, s] | a], l, r) do case t do "0" -> solve_rec(a, l, [s | r]) "1" -> solve_rec(a, [s | l], r) end end end