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