#include <bits/stdc++.h>
int main() {
  long long int a, roubles, btb, bff, cob, total_bars, offer_bars;
  scanf("%lli", &a);
  for (int i = 0; i < a; i++) {
    scanf("%lli %lli %lli %lli", &roubles, &btb, &bff, &cob);
    total_bars = roubles / cob;
    offer_bars = total_bars + (total_bars / btb) * bff;
    printf("%lli\n", offer_bars);
  }
}
