defmodule Main do def input, do: IO.read(:line) |> String.trim def ii, do: input() |> String.to_integer def li, do: input() |> String.split |> Enum.map(&String.to_integer/1) def yn(b), do: IO.puts(if b, do: "Yes", else: "No") @inf 10 ** 9 def main do t = ii() for _ <- 1..t do [a, b, c] = li() solve(a, b, c) |> IO.puts end end def solve(a, b, c) do for {a, b, c} <- [{b, a, c}, {b, c, a}, {a, c, b}, {c, a, b}] do f(a, b, c) end |> Enum.min |> then(fn x -> if x >= @inf, do: -1, else: x end) end def f(1, _, _), do: @inf def f(_, 1, _), do: @inf def f(a, b, c) do cond do a <= b -> x = b - a + 1 f(a, b-x, c) + x b <= c -> x = c - b + 1 f(a, b, c-x) + x true -> 0 end end def is_kadomatu(a, b, c) do if a == b or b == c or c == a do false else [_, x, _] = Enum.sort([a, b, c]) b != x end end end