defmodule Main do def main do {n, _} = IO.read(:line) |> Integer.parse() 1..n |> Enum.map(fn _ -> IO.read(:line) |> String.trim() |> String.split() |> (fn [s, i] -> {s, i, i |> id_to_num} end).() end) |> solve |> IO.puts() end def id_to_num(id) do case id do "iti" -> 1 "ni" -> 2 "san" -> 3 "yon" -> 4 end end def solve(books) do books |> Enum.sort(fn {s, _, i}, {t, _, j} -> cond do s == t -> i < j :else -> s < t end end) |> Enum.map(fn {s, i, _} -> [s, i] |> Enum.join(" ") end) |> Enum.join("\n") end end