#define _USE_MATH_DEFINES #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; int T; int main() { cin >> T; vector ans; while(T--) { ll A, B, K; cin >> A >> B >> K; ll l = 0, r = 3e18; while(r-l > 1) { ll mid = l+(r-l)/2; ll t = mid; t -= mid/A; t -= mid/B; t += mid/(A*B); if(t >= K) r = mid; else l = mid; } ans.push_back(r); } for(auto v : ans) cout << v << endl; }