#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  ios_base::sync_with_stdio(0);
  int t;
  cin >> t;
  while (t--) {
    ll s, a, b, c;
    cin >> s >> a >> b >> c;
    s /= c;
    int x = s / a;
    s %= a;
    long long res = x * 1LL * (a + b);
    res += s;
    cout << res << endl;
  }
  return 0;
}
