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