import sys input = sys.stdin.readline for _ in range(int(input())): L, R, A, B = map(int, input().split()) print(max(A*L+B, A*R+B))