#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    int s, a, b, c;
    cin >> s >> a >> b >> c;
    long long int initialBars = s / c;
    if (initialBars >= a) {
      long long int freeBars = (initialBars / a) * b;
      cout << initialBars + freeBars << endl;
    } else {
      cout << initialBars << endl;
    }
  }
}
