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