#include <bits/stdc++.h>
using namespace std;
int main() {
  int t;
  cin >> t;
  while (t--) {
    long long s, a, b, c, ans = 0, p = 0, y = 0;
    cin >> s >> a >> b >> c;
    ans = s / c;
    p = ans / a;
    y = ans + p * b;
    cout << y << endl;
  }
}
