#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;} using ull=unsigned long long; int main(){ ios::sync_with_stdio(false); std::cin.tie(nullptr); int T; cin>>T; while(T--){ ull A,B,K; cin>>A>>B>>K; ull l=A*B/gcd(A,B); ull ng=0,ok=numeric_limits::max(); while(ok-ng>1){ ull mid=(ok+ng)/2; if(mid-mid/A-mid/B+mid/l>=K)ok=mid; else ng=mid; } cout<