#include using ll=long long; using lll=__int128; using namespace std; ll a,b,k; lll like_gcd(lll a,lll b,lll c,lll n) { if(a==0)return b/c*(n+1); if(a>=c||b>=c)return n*(n+1)/2*(a/c)+(n+1)*(b/c)+like_gcd(a%c,b%c,c,n); lll m=(a*n+b)/c; if(m==0)return 0; return n*m-like_gcd(c,c-b-1,a,m-1); } ll check(lll c) { return like_gcd(a,c%a,b,c/a)+c/a+1; } void solve() { scanf("%lld%lld%lld",&a,&b,&k);++k;ll E=__gcd(a,b); if(k>(a-1)*(b-1)/2)printf("%lld\n",k+(a-1)*(b-1)/2-1); else { ll l=0,r=a*b; while(l<=r) { ll mid=(l+r)/2; if(check(mid)>=k)r=mid-1; else l=mid+1; } printf("%lld\n",(r+1)*E); } } int main() { int T;scanf("%d",&T); while(T--)solve(); return 0; }