#include <bits/stdc++.h>
using namespace std;
signed main() {
  long long t;
  cin >> t;
  while (t--) {
    long long s, a, b, c;
    cin >> s >> a >> b >> c;
    long long choc = s / c;
    long long x = choc / a;
    long long y = choc % a;
    long long answer = x * (a + b) + y;
    cout << answer << endl;
  }
  return 0;
}
