from collections import *
from itertools import *
from functools import *
from heapq import *
import sys,math
input = sys.stdin.readline

def answer():
    
    L,R,A,B = map(int,input().split())
    f = lambda x: A*x + B
    print(max(f(L),f(R)))
    
    
    
for _ in range(int(input())):
    answer()