#include #include using namespace std; int main() { cin.tie(nullptr)->sync_with_stdio(false); int T; cin >> T; while (T--) { long long A, B, K; cin >> A >> B >> K; const auto l = std::lcm(A, B); long long ng = K - 1, ok = 1LL << 62; while (ok - ng > 1) { const auto mid = (ok + ng) / 2; auto nin = mid - mid / A - mid / B + mid / l; if (nin >= K) { ok = mid; } else { ng = mid; } } cout << ok << '\n'; } }