#include #include #define rep(i,n) for(int i=0;i vi; typedef vector vl; typedef vector> vvi; typedef vector> vvl; typedef long double ld; typedef pair P; ostream& operator<<(ostream& os, const modint& a) {os << a.val(); return os;} template ostream& operator<<(ostream& os, const static_modint& a) {os << a.val(); return os;} template istream& operator>>(istream& is, vector& v){int n = v.size(); assert(n > 0); rep(i, n) is >> v[i]; return is;} template ostream& operator<<(ostream& os, const pair& p){os << p.first << ' ' << p.second << "\n"; return os;} template ostream& operator<<(ostream& os, const vector& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : " "); return os;} template ostream& operator<<(ostream& os, const vector>& v){int n = v.size(); rep(i, n) os << v[i] << (i == n - 1 ? "\n" : ""); return os;} void solve(){ ll a, b, k; cin >> a >> b >> k; long long ng = 0, ok = 7007007007007007007; while(ok - ng > 1){ long long x = (ok + ng) / 2; long long cnt = x - x / a - x / b + x / lcm(a, b); if(cnt >= k) ok = x; else ng = x; } cout << ok << "\n"; } int main(){ int t; cin >> t; rep(i, t) solve(); return 0; }