publicstaticvoidmain(String[] args) { // TODO Auto-generated method stub InputReader in=newInputReader(System.in); PrintWriter out=newPrintWriter(System.out); int T=in.nextInt(); while(T-->0){ int n=in.nextInt(); int m=in.nextInt(); int p=in.nextInt(); int q=in.nextInt(); int ans=0,has=0; if (m*p>q) ans+=n/m*q; else ans+=n/m*m*p; ans+=n%m*p; if ((n+m)/m*q<ans) ans=(n+m)/m*q; out.println(ans); } out.flush(); out.close(); }