#include<bits/stdc++.h>
using namespace std;
int main(){
freopen("haha.in","r",stdin);
freopen("haha.out","w",stdout);
long long k,x,y,t;
cin>>k;
for(int i = 1;i<=k;i++){
cin>>x>>y>>t;
if(t==0){
cout<<__gcd(x,y)<<endl;
}else{
cout<<x*y/__gcd(x,y)<<endl;
}
}
fclose(stdin);
fclose(stdout);
return 0;
}