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