T = gets.to_i T.times do l, r, a, b = gets.split.map(&:to_i) if a >= 0 puts r * a + b else puts l * a + b end end