#include using ll = unsigned long long; int main(void){ int t; std::cin>>t; while(t--){ ll a, b, k; std::cin>>a>>b>>k; ll l = 0, r = 4e18 + 100; while(l + 1 < r){ ll m = (l+r) / 2; ll cnt = m - m/ a - m / b + m / (a*b); if(cnt >=k){ r = m; } else{ l = m; } } std::cout << r << std::endl; } }