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