#include #include #include using namespace std; int main() { /*#ifndef ONLINE_JUDGE freopen("in.cpp","r",stdin); freopen("out.cpp","w",stdout); #endif // ONLINE_JUDGE*/ int n,m,p,q; int t; while(scanf("%d",&t)!=EOF) { while(t--) { scanf("%d %d %d %d",&n,&m,&p,&q); int cost1=n*p; int cost2=n/m*q; if(n%m*p