defmodule Main do @spec input() :: binary() 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() for _ <- 1..t do [l, r, a, b] = li() if a >= 0 do a * r + b else a * l + b end |> IO.puts end end end