#include <bits/stdc++.h>
using namespace std;
int const N = 15e4 + 5, M = 6 + 5, OO = 0x3f3f3f3f;
int t;
long long s, a, b, c, ans;
int main() {
  scanf("%d", &t);
  while (t--) {
    ans = 0;
    scanf("%I64d %I64d %I64d %I64d", &s, &a, &b, &c);
    ans += s / c;
    ans += ((ans / a) * b);
    printf("%I64d\n", ans);
  }
  return 0;
}
