#include <bits/stdc++.h>
using namespace std;
pair<int, int> operator+(pair<int, int> A, pair<int, int> B) {
  return pair<int, int>(A.first + B.first, A.second + B.second);
}
pair<int, int> operator-(pair<int, int> A, pair<int, int> B) {
  return pair<int, int>(A.first - B.first, A.second - B.second);
}
pair<int, int> operator*(int k, pair<int, int> A) {
  return pair<int, int>(k * A.first, k * A.second);
}
int operator*(pair<int, int> A, pair<int, int> B) {
  return A.first * B.second - A.second * B.first;
}
int ccw(pair<int, int> A, pair<int, int> B, pair<int, int> C) {
  int t = (B - A) * (C - A);
  if (t > 0) return 1;
  if (t < 0) return -1;
  return 0;
}
long t;
long long d, a, b, c, s;
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> s >> a >> b >> c;
    long long d = s / c;
    cout << d + b * (d / a) << "\n";
    ;
  }
  return 0;
}
