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