#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long ans = 0;
    int s, a, b, c;
    cin >> s >> a >> b >> c;
    long long w = s / c;
    ans += w;
    ans += w / a * b;
    cout << ans << endl;
  }
  return 0;
}
