#include <bits/stdc++.h>
using namespace std;
const long long N = 2e5 + 5, inf = 1e18 + 100;
void solve() {
  long long s, a, b, c;
  cin >> s >> a >> b >> c;
  long long k = s / c;
  cout << k + k / a * b << '\n';
}
signed main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  long long q;
  cin >> q;
  while (q--) solve();
  return 0;
}
