#include <bits/stdc++.h>
using namespace std;
int T;
long long s, a, b, c;
int main(int argc, const char* argv[]) {
  cin >> T;
  while (T--) {
    cin >> s >> a >> b >> c;
    cout << (s / c) + ((s / c) / a) * b << "\n";
  }
  return 0;
}
