#include <bits/stdc++.h>
int main() {
  int time;
  long long int a, b, c, d;
  long long int x, y, z;
  scanf("%d", &time);
  for (int i = 0; i < time; i++) {
    scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
    x = 0;
    y = 0;
    x = a / d;
    if (x >= b) {
      y = x + x / b * c;
    } else if (x < b) {
      y = x;
    }
    printf("%lld\n", y);
  }
}
