#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  long long has, cost, manytofree, musttofree;
  cin >> t;
  while (t--) {
    cin >> has >> musttofree >> manytofree >> cost;
    cout << (has / cost) + manytofree * (has / (musttofree * cost)) << endl;
  }
  return 0;
}
