#include <bits/stdc++.h>
using namespace std;
long long lol(long long a, long long b) { return a / b; }
int main() {
  int n, a[300009];
  cin >> n;
  while (n--) {
    long long s, a, b, c;
    cin >> s >> a >> b >> c;
    long long nani = s / c;
    long long nande = nani / a;
    long long kirito = nande * (a + b);
    long long asuna = kirito + nani % a;
    cout << asuna << endl;
  }
}
