#include using namespace std; using ulong=unsigned long; ulong gcd(ulong a,ulong b){ if(!b)return a; else return gcd(b,a%b); } ulong lcm(ulong a,ulong b){ return a/gcd(a,b)*b; } /*  l以上r以下の整数で、aまたはbで割り切れる数の個数 */ ulong count(ulong a, ulong b, ulong l, ulong r){ ulong g=gcd(a,b); //最大公約数 ulong m=a/g*b; //最小公倍数 ulong k=l-1L; return (r/a+r/b-r/m)-(k/a+k/b-k/m); } ulong solve(ulong a, ulong b, ulong k){ ulong res=k; ulong cnt=count(a,b,1L,res); while(cnt){ ulong r=res+1L; res+=cnt; cnt=count(a,b,r,res); } return res; } int main(){ int t; cin >> t; while(t--){ ulong a,b,k; cin >> a >> b >> k; cout << solve(a,b,k) << endl; } return 0; }