#include <bits/stdc++.h>
using namespace std;
inline char gch() {
  static char buf[100010], *h = buf, *t = buf;
  return h == t && (t = (h = buf) + fread(buf, 1, 100000, stdin), h == t)
             ? EOF
             : *h++;
}
inline void re(long long &x) {
  x = 0;
  char a;
  bool b = 0;
  while (!isdigit(a = getchar())) b = a == '-';
  while (isdigit(a)) x = x * 10 + a - '0', a = getchar();
  if (b == 1) x = -x;
}
long long f[100010], T, x, y, z, ans;
inline void init() {
  for (register int i = 1; i <= 100000; i++)
    for (register int j = i; j <= 100000; j += i) f[j]++;
}
long long gcd(long long a, long long b) { return (b == 0) ? a : gcd(b, a % b); }
int main() {
  re(T);
  init();
  while (T--) {
    re(x), re(y), re(z), ans = 0;
    long long xy = gcd(x, y), xz = gcd(x, z), yz = gcd(y, z), xyz = gcd(xy, z);
    ans += f[x] * f[y] * f[z];
    ans -= f[xy] * (f[xy] - 1) / 2ll * f[z];
    ans -= f[xz] * (f[xz] - 1) / 2ll * f[y];
    ans -= f[yz] * (f[yz] - 1) / 2ll * f[x];
    ans += f[xyz] * (f[xyz] - 1);
    ans += f[xyz] * (f[xyz] - 1) * (f[xyz] - 2) * 4ll / 6ll;
    ans += (f[xy] - f[xyz]) * f[xyz] * (f[xyz] - 1) / 2ll;
    ans += (f[xz] - f[xyz]) * f[xyz] * (f[xyz] - 1) / 2ll;
    ans += (f[yz] - f[xyz]) * f[xyz] * (f[xyz] - 1) / 2ll;
    ans -= (f[xy] - f[xyz]) * (f[xz] - f[xyz]) * (f[yz] - f[xyz]);
    printf("%I64d\n", ans);
  }
}
