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") def main do # t = ii() # s = File.read!("/dev/stdin") |> String.split("\n", trim: true) s = IO.binread(:eof) |> String.split("\n", trim: true) for t <- tl(s) do [a, b, c, x, y, z] = t |> String.split |> Enum.map(&String.to_integer/1) case kadomatu(a, b, c) do [] -> -1 res -> res |> Enum.map(fn {a1, b1, c1} -> x*(a-a1) + y*(b-b1) + z*(c-c1) end) |> Enum.min end end |> Enum.join("\n") |> IO.puts end @spec kadomatu(any(), any(), any()) :: list() def kadomatu(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 |> List.flatten |> Enum.uniq |> Enum.filter(fn {x, y, z} -> a >= x and b >= y and c >= z end) end def f(1, _, _), do: [] def f(_, 1, _), do: [] def f(a, b, c) do cond do a <= b -> f(a, a-1, c) b <= c -> f(a, b, b-1) true -> [{a, c, b}, {b, c, a}, {b, a, c}, {c, a, b}] end end end