#include using namespace std; int main(){ #define int long long int q,a,b,c,x,y,z; cin >> q; while(q--){ cin >> a >> b >> c; x=0,y=0,z=c; while(z/a!=x||z/b!=y) x = z/a,y = z/b,z=(c+x+y)-z/lcm(a,b); cout << z << endl; } }