#include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; ll A, B, K; bool judge(ll X){ return X-(X/A+X/B-X/lcm(A, B)) >= K; } void solve(){ cin >> A >> B >> K; ll l=0, r=4e18, c; while(r-l>1){ c = (l+r)/2; if (judge(c)) r=c; else l=c; } cout << r << endl; return; } int main(){ ll T; cin >> T; while(T){ T--; solve(); } return 0; }