#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; } cout << ok << endl; } 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; }