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