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