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