#include <bits/stdc++.h>
using namespace std;
const long long int INF = (1LL << 60) - 1;
const long long int MAX = 1000000001;
const long long int mod = 1000000007;
long long int fast_exp(long long int base, long long int exp, long long int m) {
  long long int res = 1;
  while (exp > 0) {
    if (exp % 2 == 1) {
      res = (res * base) % m;
    }
    base = (base * base) % m;
    exp /= 2;
  }
  return res % m;
}
typedef struct node {
  long long int b, i;
  node() {
    b = 0;
    i = 0;
  }
} Node;
bool comp(struct node& A, struct node& B) { return A.b < B.b; }
int main() {
  ios ::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  long long int t, s, a, b, c;
  cin >> t;
  while (t--) {
    cin >> s >> a >> b >> c;
    if (a * c > s) {
      cout << s / c << '\n';
      continue;
    }
    long long int temp = s / (a * c);
    s -= (temp * c * a);
    cout << temp * b + a * temp + s / c << '\n';
  }
  return 0;
}
