#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long s, a, b, c, k, m, ans = 0, p;
    cin >> s >> a >> b >> c;
    k = s / c;
    ans = k;
    p = k / a;
    m = s % c;
    p = p * b;
    ans += p;
    cout << ans << endl;
  }
  return 0;
}
