#include <bits/stdc++.h>
using namespace std;
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  long long n, i, t, j, m, s, x, y, p, c, b, a, z, sum = 0, digits = 0, total;
  long long minm = 1000000000000;
  cin >> t;
  while (t--) {
    sum = 0;
    cin >> s >> a >> b >> c;
    x = s / (a * c);
    sum += (a + b) * x;
    sum += (s - (x * a * c)) / c;
    cout << sum << endl;
  }
  return 0;
}
