1 //#include <bits/stdc++.h>
2 #include <iostream>
3 #include <cstring>
4 #include <cstdio>
5 #include <cmath>
6 #include <algorithm>
7 #include <vector>
8 #include <map>
9 #include <set>
10 #include <stack>
11 #include <queue>
12 #define LL long long
13 #define pii pair<int,int>
14 #define INF 0x7f7f7f7f
15 using namespace std;
16 const int N=100;
17
18 int main()
19 {
20 //freopen("input.txt", "r", stdin);
21 int n, m, t, p, q;
22 cin>>t;
23 while(t--)
24 {
25 scanf("%d%d%d%d",&n,&m,&p,&q);
26 int tmp=n/m*q + (n%m)*p;
27 int tmp2=min((n/m+1)*q, tmp);
28 int ans=min(n*p,tmp2);
29 printf("%d
", ans);
30
31 }
32 return 0;
33 }