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() |> Enum.map(&String.to_integer/1) end) |> solve |> IO.puts() end def solve(x) do solve_rec(x, -1) end def solve_rec([], a) do a end def solve_rec([[x, y] | t], a) do cond do y <= x || (a != -1 && a != y - x) -> -1 true -> solve_rec(t, y - x) end end end