#include <bits/stdc++.h>
int main(int argc, char **argv) {
  unsigned long long int t;
  scanf("%llu", &t);
  for (unsigned long long int k = 0; k < t; k++) {
    unsigned long long int a, b, c, d;
    scanf("%llu %llu %llu %llu", &a, &b, &c, &d);
    printf("%llu\n", (a / d) + ((a / d) / b) * c);
  }
  return 0;
}
