#include <bits/stdc++.h>
using namespace std;
const int MOD = 1000000007;
long double PI = 4 * atan(1);
long long t, second, a, b, c;
int main() {
  ios::sync_with_stdio(0), cin.tie(0);
  cin >> t;
  while (t--) {
    cin >> second >> a >> b >> c;
    long long x = second / c;
    long long y = x / a;
    long long ans = x + y * b;
    cout << ans << "\n";
  }
  return 0;
}
