include<bits/stdc++.h>
using namespace std;
define int long long
namespace yspm{
inline int read()
{
int res=0,f=1; char k;
while(!isdigit(k=getchar())) if(k'-') f=-1;
while(isdigit(k)) res=res10+k-'0',k=getchar();
return resf;
}
const int N=1e5+10,Q=2e4+10,mod=1ll<<31;
struct node{
int n,m,a,id;
bool operator <(const node p)const{return a<p.a;}
}q[Q];
int cnt,pri[N],mu[N],fl[N],d[N],id[N],ans[Q];
inline bool cmp(int p,int q){return d[p]<d[q];}
inline void prework()
{
mu[1]=1;
for(int i=2;i<N;++i)
{
if(!fl[i]) mu[i]=-1,pri[++cnt]=i;
for(int j=1;j<=cnt&ipri[j]<N;++j)
{
fl[ipri[j]]=1;
if(i%pri[j]0) break;
else mu[ipri[j]]=-mu[i];
}
}
for(int i=1;i<N;++i) for(int j=i;j<N;j+=i) d[j]+=i;
for(int i=1;i<N;++i) id[i]=i;
sort(id+1,id+N,cmp);
return ;
}
inline int upd(int x,int y){return x+y>=mod?x+y-mod:x+y;}
struct BIT{
int c[N];
inline int lowbit(int x){return x&(-x);}
inline void add(int x,int d){for(;x<N;x+=lowbit(x)) c[x]=upd(c[x],d); return ;}
inline int query(int x){int res=0; for(;x;x-=lowbit(x)) res=upd(res,c[x]); return res;}
}t;
inline int query(int n,int m)
{
if(n>m) swap(n,m);int ans=0;
for(int l=1,r;l<=n;l=r+1)
{
r=min(n/(n/l),m/(m/l));
ans+=(t.query(r)-t.query(l-1)+mod)%mod(n/l)%mod(m/l)%mod;
ans%=mod;
} return ans;
}
signed main()
{
int T=read(); prework();
for(int i=1;i<=T;++i) q[i].n=read(),q[i].m=read(),q[i].a=read(),q[i].id=i;
sort(q+1,q+T+1);
int now=1;
for(int i=1;i<=T;++i)
{
while(now<N&&d[id[now]]<=q[i].a)
{
for(int i=1;iid[now]<N;++i) t.add(iid[now],mu[i]d[id[now]]%mod);
now++;
}
ans[q[i].id]=query(q[i].n,q[i].m);
}
for(int i=1;i<=T;++i) printf("%lld
",ans[i]);
return 0;
}
}
signed main(){return yspm::main();}