#include <bits/stdc++.h>
int main() {
  long long int a, b, c, d, x;
  int t;
  scanf("%d", &t);
  while (t--) {
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);
    x = a / d + (((a / d) / b) * c);
    printf("%lld\n", x);
  }
  return 0;
}
