template<typename T> inlinevoidqread(T &x) { x = 0; REG int f = 0; REG char ch = getchar(); while(!isdigit(ch)) f |= (ch == '-'), ch = getchar(); while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48), ch = getchar(); x = f ? -x : x; }
int T, bd; int ans[maxt];
structqust{ int n, m, a, ser; constbooloperator < (const qust &th) const {return a == th.a ? ser < th.ser : a < th.a;} } t[maxt];
structdpair{ int v; int s; constbooloperator < (const dpair &th) const {return s == th.s ? v < th.v : s < th.s;} } d[maxn]; int pt;
int pr[maxn], pc; bool ip[maxn]; int mu[maxn]; int sgm[maxn], pw[maxn];
voidlinear_sieve() { mu[1] = 1, sgm[1] = 1, pw[1] = 1; for(REG int i = 2; i <= bd; i++) { if(!ip[i]) pr[++pc] = i, mu[i] = -1, sgm[i] = i + 1, pw[i] = i * i; for(REG int j = 1; j <= pc && 1ll * i * pr[j] <= bd; j++) { REG int c = i * pr[j]; ip[c] = true; if(i % pr[j]) mu[c] = -mu[i], sgm[c] = sgm[i] * (pr[j] + 1), pw[c] = pr[j] * pr[j]; else {pw[c] = pw[i] * pr[j], sgm[c] = 1ll * sgm[i] * (pw[c] - 1) / (pw[i] - 1); break;} } } for(REG int i = 1; i <= bd; i++) d[i].v = i, d[i].s = sgm[i]; }
int c[maxn];
inlineintlowbit(int p){return p & (-p);} inlinevoidupd(int p, int x){while(p <= bd) c[p] += x, p += lowbit( p );} inlineintqry(int p){REG int res = 0; while(p > 0) res += c[p], p -= lowbit( p ); return res;} inlineintqry(int l, int r){returnqry(r) - qry(l - 1);}
intwork() { qread(T);
for(REG int i = 1; i <= T; i++) qread(t[i].n), qread(t[i].m), qread(t[i].a), t[i].ser = i, bd = max(bd, min(t[i].n, t[i].m));
linear_sieve(); sort(t + 1, t + T + 1); sort(d + 1, d + bd + 1);
for(REG int i = 1; i <= T; i++) {
while(pt < bd && d[pt + 1].s <= t[i].a) { REG int cur = d[++pt].v; REG int curd = d[pt].s; for(REG int k = 1; 1ll * cur * k <= bd; k++) upd(cur * k, curd * mu[k]); }
REG int N = t[i].n, M = t[i].m, ser = t[i].ser; if(N > M) swap(N, M); for(REG int l = 1, r; l <= N; l = r + 1) { r = min(N / (N / l), M / (M / l)); ans[ser] += (N / l) * (M / l) * qry(l, r); } }
for(REG int i = 1; i <= T; i++) printf("%lld\n", ans[i] & 2147483647); return0; } }