#include using namespace std; using ll = long long; #define rep(i,m,n) for(int i=m; i bool chmin(T& a, T b){ if(a > b){a = b; return true;} return false; } template bool chmax(T& a, T b){ if(a < b){a = b; return true;} return false; } template T gcd(T a, T b){ return a % b ? gcd(b, a % b) : b; } template T lcm(T a, T b){ return a / gcd(a, b) * b; } int main(){ ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin >> T; while(T--){ ll A, B, K; cin >> A >> B >> K; ll lo = 0LL, hi = 1LL << 62, L = lcm(A, B), mid, x; while(abs(lo - hi) > 1LL){ mid = (lo + hi) / 2LL; x = mid - (mid / A + mid / B - mid / L); (x >= K ? hi : lo) = mid; } cout << hi << endl; } return 0; }