#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; } cout << l << endl; return; } int main(){ ll T; cin >> T; while(T){ T--; solve(); } return 0; }