#include using namespace std; typedef long long ll; typedef pair P; #define REP(i,n) for(int i=0;i1){ ll mid=(ng+ok)/2; if(k+mid/a+mid/b-mid/L<=mid) ok=mid; else ng=mid; } vector v; v.push_back(ok); if(ok>1) v.push_back(ok-1); if(ok>2) v.push_back(ok-2); if(ok>3) v.push_back(ok-3); for(int i=0;i<(int)v.size();i++) if(v[i]%a!=0 && v[i]%b!=0){ cout << v[i] << endl; break; } } int main(void){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int i,j; int T; cin >> T; while(T--){ ll A,B,K; cin >> A >> B >> K; L=lcm(A,B); find(A,B,K); } return 0; }