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