#include using namespace std; using ll = long long; void solve(){ ll a, b, c, l; cin >> a >> b >> c; l = lcm(a, b); auto f=[&](ll z){ return z-z/a-z/b+z/l >= c; }; ll ng = 0, ok = 9e18, mid; while(ok-ng>1){ mid = (ok+ng)/2; if (f(mid)) ok = mid; else ng = mid; } cout << ok << endl; } int main(){ cin.tie(nullptr); ios_base::sync_with_stdio(false); int t; cin >> t; while(t--){ solve(); } return 0; }