#include <bits/stdc++.h>
using namespace std;
long long s, c, a, b;
int t;
int main() {
  cin >> t;
  for (int i = 1; i <= t; i++) {
    cin >> s >> a >> b >> c;
    s = floor(s / c);
    a = s + floor(s / a) * b;
    cout << a << endl;
  }
  return 0;
}
