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