#define rep(i,n) for(int i=0;i<(int)(n);i++) #define ALL(v) v.begin(),v.end() typedef long long ll; #include using namespace std; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int t; cin>>t; while(t--){ ll a,b,k; cin>>a>>b>>k; ll c=lcm(a,b); auto f=[&](ll x){ return x-x/a-x/b+x/c; }; ll ok=8e18+1,ng=0; while(ok-ng>1){ ll mid=(ok+ng)/2; if(f(mid)>=k) ok=mid; else ng=mid; } cout<