#include using namespace std; int main(){ int T; cin >> T; for (int i = 0; i < T; i++){ long long A, B, K; cin >> A >> B >> K; long long L = lcm(A, B); long long tv = 0, fv = 6100000000000000000; while (fv - tv > 1){ long long mid = tv + (fv - tv) / 2; long long cnt = mid - mid / A - mid / B + mid / L; if (cnt <= K){ tv = mid; } else { fv = mid; } } cout << tv << endl; } }