#include <bits/stdc++.h>
using namespace std;
int arr[4];
int main() {
  long long t, a, b, c, s;
  long long bars;
  cin >> t;
  while (t) {
    cin >> s >> a >> b >> c;
    bars = (s / c) + ((s / c) / a) * b;
    cout << bars << endl;
    t--;
  }
  return 0;
}
