import sequtils, strutils let t = parseInt readLine stdin var l, r, a, b: int for _ in 0..<t: (l, r, a, b) = stdin.readLine.split.map parseInt if a > 0: echo a * r + b else: echo a * l + b