#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
typedef pair<int,int> abcd;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
if (p1==p2) { p2=(p1=buf)+fread(buf,1,100000,stdin); if (p1==p2) return EOF; }
return *p1++;
}
inline void read(int &x){
char c=nc(),b=1;
for (;!(c>='0' && c<='9');c=nc()) if (c=='-') b=-1;
for (x=0;c>='0' && c<='9';x=x*10+c-'0',c=nc()); x*=b;
}
int maxn=0;
int prime[100005],num,vst[100005];
int mobius[100005];
abcd sig[100005];
inline void Pre()
{
mobius[1]=1;
for (int i=2;i<=maxn;i++)
{
if (!vst[i])
{
mobius[i]=-1; prime[++num]=i;
}
for (int j=1;j<=num && prime[j]*i<=maxn;j++)
{
vst[i*prime[j]]=1;
if (i%prime[j]==0)
{
mobius[i*prime[j]]=0; break;
}
else
mobius[i*prime[j]]=-mobius[i];
}
}
for (int i=1;i<=maxn;i++)
for (int j=i;j<=maxn;j+=i)
sig[j].first+=i;
for (int i=1;i<=maxn;i++)
sig[i].second=i;
sort(sig+1,sig+maxn+1);
}
struct que{
int n,m,a,idx;
bool operator < (const que& B) const{
return a<B.a;
}
}Q[100005];
int Case;
namespace BIT{
#define lowbit(x) (x)&-(x)
int c[100005];
inline void add(int x,int r){
for (int i=x;i<=maxn;i+=lowbit(i))
c[i]+=r;
}
inline int sum(int x){
int ret=0;
for (int i=x;i;i-=lowbit(i))
ret+=c[i];
return ret;
}
}
int anss[100005];
int main()
{
read(Case);
for (int i=1;i<=Case;i++)
{
read(Q[i].n); read(Q[i].m); read(Q[i].a); Q[i].idx=i;
if (Q[i].n>Q[i].m) swap(Q[i].n,Q[i].m);
maxn=max(maxn,Q[i].n);
}
Pre();
sort(Q+1,Q+Case+1);
int lasta=1;
for(int i=1;i<=Case;i++){
int newa=upper_bound(sig+1,sig+maxn+1,make_pair(Q[i].a+1,-1))-sig-1;
for(int j=lasta;j<=newa;j++)
for(int k=sig[j].second;k<=maxn;k+=sig[j].second)
BIT::add(k,sig[j].first*mobius[k/sig[j].second]);
for(int j=1,k;j<=Q[i].n;j=k+1){
k=min(Q[i].n/(Q[i].n/j),Q[i].m/(Q[i].m/j));
anss[Q[i].idx]+=(BIT::sum(k)-BIT::sum(j-1))*(Q[i].n/j)*(Q[i].m/j);
}
lasta=newa+1;
}
for(int i=1;i<=Case;i++)
printf("%d\n",anss[i]&0x7fffffff);
}