#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int t;
  cin >> t;
  while (t--) {
    long long s, a, b, c;
    cin >> s >> a >> b >> c;
    long long ans = (s / (a * c)) * (a + b);
    long long r = s % (a * c);
    ans += (r / c);
    cout << ans << '\n';
  }
}
