#include <bits/stdc++.h>
using namespace std;
void solve() {
  long long ans = 0;
  long long a, b, c, s;
  cin >> s >> a >> b >> c;
  ans = s / c + (s / c / a) * b;
  cout << ans << endl;
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
