#include <bits/stdc++.h>
using namespace std;
int main() {
  int T;
  scanf("%d", &T);
  while (T--) {
    long long money, theCount, add, one;
    scanf("%lld %lld %lld %lld", &money, &theCount, &add, &one);
    long long ans = 0;
    ans = money / one + (money / (theCount * one)) * add;
    printf("%lld\n", ans);
  }
  return 0;
}
