#include <bits/stdc++.h>
#define pii pair<int,int>
#define fi first
#define int long long
#define se second
#define ios ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define op freopen
#define TXT "test"
#define freo if(fopen(TXT".inp","r")){op(TXT".inp","r",stdin);op(TXT".out","w",stdout);}
using namespace std;
int t,a,b,k,lcm;
int so(int m)
{
return m-(m/a+m/b-m/lcm);
}
void bs(int l,int r)
{
int m,ans;
while(l<=r)
{
m=(l+r)>>1;
if(so(m)<k)
{
ans=m;
l=m+1;
}
else
{
r=m-1;
}
}
cout<<ans+1<<"\n";
}
main()
{
ios;
freo;
cin>>t;
while(t--)
{
cin>>k>>a>>b;
lcm=a/__gcd(a,b)*b;
bs(1,k*max(a,b));
}
}
I2luY2x1ZGUgPGJpdHMvc3RkYysrLmg+CiNkZWZpbmUgcGlpIHBhaXI8aW50LGludD4KI2RlZmluZSBmaSBmaXJzdAojZGVmaW5lIGludCBsb25nIGxvbmcKI2RlZmluZSBzZSBzZWNvbmQKI2RlZmluZSBpb3MgaW9zX2Jhc2U6OnN5bmNfd2l0aF9zdGRpbyhmYWxzZSk7IGNpbi50aWUoTlVMTCk7IGNvdXQudGllKE5VTEwpOwojZGVmaW5lIG9wIGZyZW9wZW4KI2RlZmluZSBUWFQgInRlc3QiCiNkZWZpbmUgZnJlbyBpZihmb3BlbihUWFQiLmlucCIsInIiKSl7b3AoVFhUIi5pbnAiLCJyIixzdGRpbik7b3AoVFhUIi5vdXQiLCJ3IixzdGRvdXQpO30KCnVzaW5nIG5hbWVzcGFjZSBzdGQ7CmludCB0LGEsYixrLGxjbTsKaW50IHNvKGludCBtKQp7CiAgICByZXR1cm4gbS0obS9hK20vYi1tL2xjbSk7Cn0Kdm9pZCBicyhpbnQgbCxpbnQgcikKewogICAgaW50IG0sYW5zOwogICAgd2hpbGUobDw9cikKICAgIHsKICAgICAgICBtPShsK3IpPj4xOwogICAgICAgIGlmKHNvKG0pPGspCiAgICAgICAgewogICAgICAgICAgICBhbnM9bTsKICAgICAgICAgICAgbD1tKzE7CiAgICAgICAgfQogICAgICAgIGVsc2UKICAgICAgICB7CiAgICAgICAgICAgIHI9bS0xOwogICAgICAgIH0KICAgIH0KICAgIGNvdXQ8PGFucysxPDwiXG4iOwp9Cm1haW4oKQp7CiAgICBpb3M7CiAgICBmcmVvOwogICAgY2luPj50OwogICAgd2hpbGUodC0tKQogICAgewogICAgICAgIGNpbj4+az4+YT4+YjsKICAgICAgICBsY209YS9fX2djZChhLGIpKmI7CiAgICAgICAgYnMoMSxrKm1heChhLGIpKTsKICAgIH0KfQ==