// #pragma GCC target("avx2") // #pragma GCC optimize("O3") // #pragma GCC optimize("unroll-loops") #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include using namespace std; using ll = long long; using pii = pair; using pll = pair; #define TEST cerr << "TEST" << endl #define AMARI 998244353 // #define AMARI 1000000007 #define TIME_LIMIT 1980000 #define el '\n' #define El '\n' long long ococo_gcd(long long a, long long b) { if(a < b) { swap(a,b); } if(b == 0 && a != 0)return a; long long ans = a; while(a % b) { long long kari = b; b = a % b; a = kari; } return min(a, b); } ll lcm(ll a,ll b){ return (a * b) / ococo_gcd(a,b); } //[1,x]の中で、pまたはqで割り切れる数がa個以上かどうか lmはlcm(p,q)を入れる bool func(ll x,ll p,ll q,ll lm,ll a){ ll cnt1 = x - x / p,cnt2 = x - x / q,cnt3 = x - x / lm; if(cnt1 + cnt2 - cnt3 >= a)return true; else return false; } #define MULTI_TEST_CASE true void solve(void) { ll a,b,k; cin >> a >> b >> k; ll lm = lcm(a,b); ll l = 0,r = 4LL * k; while(r - l >= 2){ ll c = (r + l) / 2; if(func(c,a,b,lm,k))r = c; else l = c; } for(ll i = l; i <= r; i++){ if(func(i,a,b,lm,k)){ cout << i << el; return; } } assert(0); return; } void calc(void) { return; } signed main(void) { cin.tie(nullptr); ios::sync_with_stdio(false); calc(); int t = 1; if(MULTI_TEST_CASE) cin >> t; while(t--) { solve(); } return 0; }