using namespace std; #include void _main();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<>(i))&1) #define fi first #define se second #define pb push_back #define Endl endl #define spa " " #define YesNo(x) cout<<(x?"Yes":"No")< using namespace atcoder; //コンパイル時の引数にBLUEBERRYを渡すとdeb関数が使える #ifdef BLUEBERRY #define deb print #else #define deb #endif //!?!? #define O print //可変長引数で入力を受け取りつつ変数を宣言 inline void scan(){} template inline void scan(Head&head,Tail&... tail){std::cin>>head;scan(tail...);} #define LL(...) ll __VA_ARGS__;scan(__VA_ARGS__) #define STR(...) string __VA_ARGS__;scan(__VA_ARGS__) //vectorのcin template std::istream &operator>>(std::istream&is,std::vector&v){for(T &in:v){is>>in;}return is;} //vectorのcout template std::ostream &operator<<(std::ostream&os,const std::vector&v){for(auto it=std::begin(v);it!=std::end(v);){os<<*it<<((++it)!=std::end(v)?" ":"");}return os;} //x,y,x,yを渡すとldで距離を返す long double my_distance(long double xi,long double yi,long double xj,long double yj){return sqrt(abs((xi-xj)*(xi-xj))+abs((yi-yj)*(yi-yj)));} //可変長引数のprint関数 void print(){cout << '\n';} template void print(const T& a, const Ts&... b){cout << a;(cout << ... << (cout << ' ', b));cout << '\n';} //可変長引数のmin template constexpr auto min(T... a){return min(initializer_list>{a...});} //可変長引数のmax template constexpr auto max(T... a){return max(initializer_list>{a...});} templateinline bool chmax(T&a,U b){if(ainline bool chmin(T&a,U b){if(a>b){a=b;return 1;}return 0;} //Union-Find from https://zenn.dev/reputeless/books/standard-cpp-for-competitive-programming/vi((b%2==0?b-1:b)+2-(a%2==0?a+1:a))/2er/union-find class UnionFind{public:UnionFind()=default;explicit UnionFind(size_t n):m_parentsOrSize(n, -1){}int find(int i){if(m_parentsOrSize[i]<0){return i;}return(m_parentsOrSize[i]=find(m_parentsOrSize[i]));}void merge(int a,int b){a=find(a);b=find(b);if(a!=b){if(-m_parentsOrSize[a]<-m_parentsOrSize[b]){std::swap(a,b);}m_parentsOrSize[a]+=m_parentsOrSize[b];m_parentsOrSize[b]=a;}}bool connected(int a,int b){return (find(a)==find(b));}int size(int i){return -m_parentsOrSize[find(i)];}private:std::vectorm_parentsOrSize;}; //こめんとを付け外ししてMODを切り替える //ll MOD = INF; ll MOD = 1000000007; //ll MOD = 998244353; //回文判定 bool iskaibun(string s){ll k = s.size();rep(i,0,k/2){if(s[i]!=s[k-1-i]){return false;}}return true;} //二部グラフ判定 重みなしグラフを引数に取り、boolを返す bool isbipartite_graph(vector>&g){ll v = g.size();vectorcol(v,-1);vectorused(v,false);bool ret = true;rep(i,v){if(used[i])continue;col[i]=0;[DFS([&](auto&&f,ll pos,ll pr)->void{if(used[pos])return;used[pos]=true;for(auto to:g[pos]){if(to==pr)continue;if(used[to]&&col[pos]==col[to]){ret = false;return;}if(used[to])continue;col[to]=col[pos]^1;f(f,to,pos);}}),&i]{DFS(DFS,i,-1);}();}return ret;} //a~bの和 aza=atcoder::z_algorithm(tmp);string ret="";for (int i=from_len;i=from_len){ret+=too;i += from_len;}else{ret += tmp[i];i++;}}return ret;} //座圧する ll zaatu(vector&A){mapm;for(auto&&x:A)m[x]=0;ll ret = 0;for(auto&&[key,val]:m)val=ret++;for(auto&&x:A)x=m[x];return ret;} //約数列挙 引数に取った整数の約数のvectorを返す vectorenumdiv(ll n){vectors;for(ll i = 1;i*i<=n;i++){if(n%i==0){s.push_back(i);if(i*i!=n)s.push_back(n/i);}}return s;} //トポロジカルソート グラフ、入次数カウント、頂点数を引数で渡すと、トポロジカルソートされた頂点列を返す vector topo_sort(vector>&G,vector&nyu_cnt,ll v){vectorret;priority_queue,greater>pq;rep(i,0,v){if(nyu_cnt[i]==0)pq.push(i);}while(!pq.empty()){ll pos = pq.top();pq.pop();for(ll i:G[pos]){nyu_cnt[i]--;if(nyu_cnt[i]==0)pq.push(i);}ret.push_back(pos);}return ret;} //素因数分解 pair<素数、指数>のvectorを返す vector> soinsu_bunkai(ll x){vector>ret;rep(i,2,sqrt(x)+1){if(x%i==0){ll cnt{};while(x%i==0){x/=i;cnt++;}ret.push_back({i,cnt});}}if(x!=1)ret.push_back({x,1});return ret;} //二項係数MOD MODは上の方で設定、MAXまでのnCrをCOM(n,r)でとれる const int MAX = 5000000; ll fac[MAX], finv[MAX], invv[MAX]; void COMinit(){fac[0]=fac[1]=finv[0]=finv[1]=invv[1]=1;for(int i=2;i isprime;vector Era(int n) {isprime.resize(n, true);vector res;isprime[0] = false; isprime[1] = false;for (int i = 2; i < n; ++i) isprime[i] = true;for (int i = 2; i < n; ++i){if (isprime[i]) {res.push_back(i);for (int j = i*2; j < n; j += i) isprime[j] = false;}}return res;} using mint = modint998244353; void solve(); void _main(){ int testcase = 1; cin >> testcase; for(;testcase--;){ solve(); } } void solve(){ LL(a,b,k); ll ok = 0,ng = INF; ll g = lcm(a,b); while(abs(ok-ng)>1){ ll mid = (ok+ng)/2; ll cna = mid/a,cnb = mid/b,cnab = mid/(g); if(mid-(cna+cnb-cnab)<=k)ok=mid; else ng = mid; } O(ok); }