#include using namespace std; template T gcd(T a, T b){return b==0?a:gcd(b,a%b);} template T lcm(T a, T b){return a/gcd(a,b)*b;} int main() { ios::sync_with_stdio(false); cin.tie(nullptr); int T; cin>>T; while(T--) { long A,B,K; cin>>A>>B>>K; long C=lcm(A,B); long L=0,R=3e18; while(R-L>1) { long mid=(L+R)/2; long cnt=mid-(mid/A+mid/B-mid/C); (cnt>=K?R:L)=mid; } cout<