#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/lcm(a,b)<=mid) ok=mid; else ng=mid; } vector v; v.push_back(ok); v.push_back(ok-1); v.push_back(ok-2); for(int i=0;i<3;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; find(A,B,K); } return 0; }