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