#include <bits/stdc++.h>
const int dx[] = {0, -1, 0, 1, -1, 1, 1, -1, -2, -2, 2, 2, -1, -1, 1, 1};
const int dy[] = {-1, 0, 1, 0, 1, 1, -1, -1, -1, 1, -1, 1, -2, 2, -2, 2};
using namespace std;
int main(int argc, char const *argv[]) {
  int tc;
  scanf("%d", &tc);
  for (int i = 1; i <= tc; i++) {
    long long r, o, e, c;
    scanf("%lld %lld %lld %lld", &r, &o, &e, &c);
    long long ans = (r / (o * c)) * e + (r / (o * c)) * o + (r % (o * c)) / c;
    cout << ans << endl;
  }
  return 0;
}
