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