#include <bits/stdc++.h>
using namespace std;
const int maxv = 1e5, maxn = maxv + 10;
int t, v[8], c[8], f[maxn];
void Sieve() {
  for (int i = 1; i <= maxv; i++) {
    for (int j = i; j <= maxv; j += i) {
      f[j]++;
    }
  }
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
long long C(int n, int m) {
  if (n < m) return 0;
  long long res = 1;
  for (int i = 1; i <= m; i++) res = res * n-- / i;
  return res;
}
bool check(int a, int b, int c) {
  return ((a & 1) && (b & 2) && (c & 4)) || ((a & 1) && (b & 4) && (c & 2)) ||
         ((a & 2) && (b & 1) && (c & 4)) || ((a & 2) && (b & 4) && (c & 1)) ||
         ((a & 4) && (b & 1) && (c & 2)) || ((a & 4) && (b & 2) && (c & 1));
}
int main() {
  Sieve();
  scanf("%d", &t);
  while (t--) {
    int x, y, z, xy, xz, yz, xyz;
    scanf("%d%d%d", &x, &y, &z);
    xy = gcd(x, y), xz = gcd(x, z), yz = gcd(y, z), xyz = gcd(x, yz);
    v[1] = f[x] - f[xy] - f[xz] + f[xyz];
    v[2] = f[y] - f[xy] - f[yz] + f[xyz];
    v[4] = f[z] - f[xz] - f[yz] + f[xyz];
    v[3] = f[xy] - f[xyz];
    v[5] = f[xz] - f[xyz];
    v[6] = f[yz] - f[xyz];
    v[7] = f[xyz];
    long long ans = 0;
    for (int i = 1; i < 8; i++) {
      for (int j = i; j < 8; j++) {
        for (int k = j; k < 8; k++) {
          if (!check(i, j, k)) continue;
          c[i]++, c[j]++, c[k]++;
          long long tmp = 1;
          for (int l = 1; l < 8; l++) {
            if (!c[l]) continue;
            tmp = tmp * C(v[l] + c[l] - 1, c[l]);
          }
          ans += tmp;
          c[i] = c[j] = c[k] = 0;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
