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