#include <bits/stdc++.h>
using namespace std;
const int maxn = 5e3 + 10;
const int mod = 1e9 + 7;
const long long inf = 1e10 + 7;
const int dx[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dy[8] = {1, 0, -1, 0, -1, 1, 1, -1};
unsigned long long s, a, b, c, T;
int main() {
  cin >> T;
  while (T--) {
    cin >> s >> a >> b >> c;
    cout << (s / c) + (((s / c) / a) * b) << '\n';
  }
  return 0;
}
