#include<bits/stdc++.h>
using namespace std;
int main(){
long long T;
cin>>T;
std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
while(T--){
long long a,b,c;
cin>>a>>b>>c;
long long lm = a*b/__gcd(a,b);
long long now = lm;
while(!(lm/a>=c && lm/b>=c)) lm+=now;
cout<<lm/a+lm/b<<"\n";
}
return 0;
}