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() |> (fn [t, s] -> {t |> String.to_integer(), s} end).() end) |> solve |> IO.puts() end def solve(t) do solve_rec(t, []) end def solve_rec([], r) do r |> Enum.join() end def solve_rec([{t, s} | l], r) do case t do 0 -> solve_rec(l, r |> List.insert_at(-1, s)) 1 -> solve_rec(l, [s | r]) end end end