#include <bits/stdc++.h>
using namespace std;
long long t, a, b, c, d;
int main() {
  ios::sync_with_stdio(false);
  cin >> t;
  while (t--) {
    cin >> a >> b >> c >> d;
    cout << a / d + a / d / b * c << "\n";
  }
}
