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