#include <bits/stdc++.h>
int main() {
  unsigned long long n, s, a, b, c;
  scanf("%llu", &n);
  for (int i = 0; i < n; i++) {
    scanf("%llu%llu%llu%llu", &s, &a, &b, &c);
    printf("%llu\n", s / c + s / c / a * b);
  }
}
