#include <bits/stdc++.h>
using namespace std;
int Day12[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
int prime100[] = {2,  3,  5,  7,  11, 13, 17, 19, 23, 29, 31, 37,  41, 43,
                  47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103};
template <typename T>
inline bool isLeap(T y) {
  return (y % 400 == 0) || (y % 100 ? y % 4 == 0 : false);
}
template <typename T>
inline T BIGMOD(T A, T B, T M = 1000000007) {
  T ret = 1;
  while (B) {
    if (B & 1) ret = (ret * A) % M;
    A = (A * A) % M;
    B = B >> 1;
  }
  return ret;
}
template <typename T>
inline T BigMod(T A, T B, T M) {
  T ret = 1;
  while (B) {
    if (B & 1) ret = (ret * A) % M;
    A = (A * A) % M;
    B = B >> 1;
  }
  return ret;
}
long long int MySqrt(long long int n) {
  long long int p = sqrt(n);
  if ((p + 1) * (p + 1) <= n)
    return p + 1;
  else if (p * p <= n)
    return p;
  else
    return p - 1;
}
long long int MyPow(long long int x, long long int n) {
  if (n == 0)
    return 1;
  else if (n % 2 == 0)
    return MyPow(x * x, n / 2);
  else
    return x * MyPow(x * x, ((n - 1) / 2));
}
long long int modInverse(long long int n) {
  return BIGMOD(n, (long long int)1000000007 - 2) % 1000000007;
}
int bye() { return 0; }
int main() {
  int t;
  cin >> t;
  long long int second, a, b, c;
  for (int i = 1; i <= t; i++) {
    cin >> second >> a >> b >> c;
    long long int x = second / c;
    long long int y = x / a;
    long long int z = y * b;
    cout << x + z << '\n';
  }
}
