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