1 #include <stdio.h>
2 #include <string.h>
3 #include <algorithm>
4 using namespace std;
5 int main()
6 {
7 int T,n,m,p,q,i,j,k;
8 scanf("%d",&T);
9 while(T--)
10 {
11 scanf("%d %d %d %d",&n,&m,&p,&q);
12 if((double) p<= (double)q/m)
13 {
14 printf("%d\n",n*p);
15 }
16 else
17 {
18 int x=0;
19 for(i=1;;i++)
20 {
21 x=x+m;
22 if(x>=n)
23 break;
24 }
25 printf("%d\n",min(i*q,(i-1)*q+(n-(x-m))*p));
26 }
27 }
28 return 0;
29 }