#include <bits/stdc++.h>
using namespace std;
int main() {
  long long int t, s, i, a, b, c, sum, di;
  cin >> t;
  for (i = 0; i < t; i++) {
    sum = 0;
    di = 0;
    cin >> s >> a >> b >> c;
    sum = s / c;
    if (sum >= a) {
      di = s / (a * c);
      sum = (di * b) + sum;
    }
    cout << sum << "\n";
  }
  return 0;
}
