#include<iostream>
#include<iomanip>
#include<cmath>
using namespace std;
typedef long long ll;
int main() {
int t;
cin >> t;
while (t--) {
int n, a, b, c, d;
cin >>n>> c >> d;
a = min(c, d); b = max(c, d);
int sum = n;
int temp = n / a-1;
int n_a = 0, n_b = 0;
n_a = temp * a;
int n_rest = n - n_a;
bool f = 1;
flag:while (n_a >= a || n_b >= b) {
if (f) {
int temp_a = n_a / a;
n_a -= temp_a * a;
n_b += temp_a;
sum += temp_a;
f = 0;
}
else {
int temp_b = n_b / b;
n_b -= temp_b * b;
n_a += temp_b;
sum += temp_b;
f = 1;
}
}
int n_as = a - n_a;
int n_bs = b - n_b;
if (n_bs > n_as) {
n_a += n_as;
n_rest -= n_as;
}
else {
n_b += n_bs;
n_rest -= n_bs;
}
if (n_rest >= 0) {
goto flag;
}
cout << sum << endl;
}
}