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 |> IO.puts() end def solve(l) do l |> Enum.map(fn [a, b] -> [[bh, bm], [eh, em]] = [a, b] |> Enum.map(fn i -> i |> String.split(":") |> Enum.map(&String.to_integer/1) end) cond do bh > eh -> [bh - 24, bm] bh == eh && bm > em -> [bh, bm - 24 * 60] true -> [bh, bm] end |> (fn [bh, bm] -> eh * 60 + em - (bh * 60 + bm) end).() end) |> Enum.sum() end end