#include using namespace std; using ll=long long; #define all(v) v.begin(),v.end() #define rall(v) v.rbegin(),v.rend() template bool chmax(T &a, T b){if (a < b){a = b;return true;} else return false;} template bool chmin(T &a, T b){if (a > b){a = b;return true;} else return false;} int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int T; cin>>T; while(T--){ ll A,B,K; cin>>A>>B>>K; ll l=A*B/gcd(A,B); ll ng=0,ok=1LL<<61; while(abs(ng-ok)>1){ ll mid=(ok+ng)/2; if(mid-mid/A-mid/B+mid/l>=K)ok=mid; else ng=mid; } cout<