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