#include using namespace std; using ll = long long; ll gcd(ll a,ll b){ if(b) return gcd(b,a%b); return a; } int main(){ cin.tie(nullptr); ios::sync_with_stdio(false); int t; cin>>t; while(t--){ ll a,b,k; cin>>a>>b>>k; ll right = 8e18; ll left = 0; ll g = gcd(a,b); g = a / g * b; while(right-left>1){ ll mid = ((right-left)>>1) + left; ll cnt = mid / a + mid / b - mid / g; if(mid-cnt>=k) right = mid; else left = mid; } cout<