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