#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const long double pi = acos(-1);
const int MOD = 1e9 + 7;
const long long int LINF = 0x3f3f3f3f3f3f3f3f;
int main() {
  ios::sync_with_stdio(false);
  ;
  int tc;
  cin >> tc;
  while (tc--) {
    long long int s, a, b, c;
    cin >> s >> a >> b >> c;
    long long int qt = s / (a * c);
    long long int ans = qt * (a + b);
    s = s - qt * a * c;
    ans += s / c;
    cout << ans << "\n";
  }
  return 0;
}
