#include using namespace std; int main(){ ios_base::sync_with_stdio(false); cin.tie(nullptr); int test; cin >> test; while(test--){ long long A,B,K; cin >> A >> B >> K; if(A > B) swap(A,B); long long G = gcd(A,B),L = A*B/G; long long loop = L-(L/A+L/B-1); long long answer = L*(K/loop); K %= loop; long long low = -1,high = L-1; while(high-low > 1){ long long mid = (high+low)/2; long long now = mid-(mid/A+mid/B); if(now >= K) high = mid; else low = mid; } cout << answer+high << endl; } }