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