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