#include using namespace std; #define endl "\n" #define int long long const int MOD = 998244353; void solve() { int a, b, k; cin >> a >> b >> k; int l = 1, r = LONG_LONG_MAX; while (l < r) { int mid = l + (r - l) / 2; int count = mid - mid / a - mid / b + mid / (lcm(a, b)); if(count < k) { l = mid + 1; } else { r = mid; } } cout << l << endl; } int32_t main() { ios::sync_with_stdio(false); cin.tie(0); int T = 1; cin >> T; while (T--) { solve(); } return 0; }