#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; ll A, B, C, K; bool judge(ll X){ return X-(X/A+X/B-X/C) <= K; } void solve(){ cin >> A >> B >> K; assert(A != B); assert(2 <= A && A <= 1e9); assert(2 <= B && B <= 1e9); assert(1 <= K && K <= 1e18); C = A*B/gcd(A,B); ll l=0, r=4e18, c; while(r-l>1){ c = (l+r)/2; if (judge(c)) l=c; else r=c; } ll mi=max(1LL, l-5); for (ll X=mi; X<=l; X++){ if (X-(X/A+X/B-X/C) == K && X % A != 0 && X % B != 0){ cout << X << endl; return; } } assert(false); return; } int main(){ ll T; cin >> T; while(T){ T--; solve(); } return 0; }