#include #pragma GCC optimize("Ofast") #pragma GCC optimize("unroll-loops") using namespace std; int main() { cin.tie(0); cout.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12); int T; cin >> T; while(T--) { long long A, B, K; cin >> A >> B >> K; long long D = lcm(A, B); long long C = D - D / A - D / B + 1; long long ans = K / C * D; K %= C; long long ok = -1, ng = D + 1; while(abs(ok - ng) > 1) { long long mid = (ok + ng) >> 1; long long cnt = mid - mid / A - mid / B; if(cnt > K) { ng = mid; } else { ok = mid; } } cout << ans + ok << '\n'; } return 0; }