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