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