#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;
    int d = (s / c);
    int k = d / a;
    long long int ans = (long long int)k * (long long int)b + (long long int)d;
    cout << ans << endl;
  }
  return 0;
}
