#include using namespace std; typedef long long ll; ll MAX = 4e18; int t; ll a, b, k, g; ll gcd(ll a, ll b) { if (a % b == 0) { return b; } else { return gcd(b, a % b); } } ll lcm(ll a, ll b) { return a * b / gcd(a, b); } ll f(ll x) { return x - (x / a) - (x / b) + (x / g); } ll calc(ll left, ll right) { ll mid = (left + right) / 2; ll cal = f(mid); if (cal == k) { ll x = mid; x = mid; while (f(x) == k) { if (x % a != 0 && x % b != 0) { return x; } x--; } } else if (cal > k) { return calc(left, mid); } else if (cal < k) { return calc(mid + 1, right); } } int main(void) { cin >> t; vector ans; while (t > 0) { cin >> a >> b >> k; g = lcm(a, b); ll res = calc(1, MAX); ans.push_back(res); t--; } for (int i = 0; i < ans.size(); i++) { cout << ans[i] << endl; } return 0; }