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