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