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