import java.util.*; import java.io.*; import java.math.*; import java.util.stream.Stream; public class Main{ static PrintWriter output; static Scanner sc; static void solve(){ int t = ni(); while(t-->0) { int l = ni(); int r = ni(); int a = ni(); int b = ni(); int max = -100000000; max = Math.max(max,calc(l,r,a,b)); output.println(max); } } static int calc(int l,int r,int a,int b) { int max = -100000000; for(int i=l ; i<=r ; i++) max = Math.max(max,a*i+b); return max; } public static void main(String[] args) throws IOException{ output = new PrintWriter(System.out); sc = new Scanner(System.in); solve(); output.flush(); } static int ni(){ return sc.nextInt();} static long nl(){ return sc.nextLong();} static String ns(){return sc.next();} static BigInteger bi(){return sc.nextBigInteger();} static BigDecimal bd(){return sc.nextBigDecimal();} static Map counter(long [] A) { HashMap count = new HashMap<>(); for(int i=0;i