#include <bits/stdc++.h>
using namespace std;
int t, s, a, b, c;
int main() {
  scanf("%d ", &t);
  while (t--) {
    scanf("%d %d", &s, &a);
    scanf("%d %d", &b, &c);
    long long res = (long long)s / c;
    res += (long long)(res / a) * b;
    cout << res << endl;
  }
}
