#include <bits/stdc++.h>
using namespace std;
const int inf = 1e9 + 5;
void solve() {
  long long s, a, b, c;
  cin >> s >> a >> b >> c;
  unsigned long long ans = 0;
  long long d = s / (a * c);
  ans = d * a + d * b;
  long long o = s % (a * c);
  if (o >= c) {
    ans += o / c;
  }
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  cin >> t;
  while (t--) solve();
}
