#include <bits/stdc++.h>
using namespace std;
const int maxn = 2007;
const int mod = 1e9 + 7;
int main(void) {
  int q;
  cin >> q;
  while (q--) {
    long long s, a, b, c;
    cin >> s >> a >> b >> c;
    long long ans = (s / (c * a)) * a + (s / (c * a)) * b + (s % (c * a)) / c;
    cout << ans << endl;
  }
  return 0;
}
