#include <bits/stdc++.h>
using namespace std;
int t;
long long x, y, z;
long long xy, xz, yz, xyz;
long long di[100010], f[10];
long long is[100010];
long long ans, sum;
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long Cnm(int n, int m) {
  long long sum = 1;
  for (int i = 1; i <= m; i++) sum = sum * (n - i + 1) / i;
  return sum;
}
void init() {
  xy = gcd(x, y);
  yz = gcd(y, z);
  xz = gcd(x, z);
  xyz = gcd(xy, z);
  f[7] = di[xyz];
  f[6] = di[yz] - di[xyz];
  f[5] = di[xz] - di[xyz];
  f[4] = di[z] - di[xz] - di[yz] + di[xyz];
  f[3] = di[xy] - di[xyz];
  f[2] = di[y] - di[xy] - di[yz] + di[xyz];
  f[1] = di[x] - di[xy] - di[xz] + di[xyz];
}
bool check(int a, int b, int c) {
  if ((a & 1) && (b & 2) && (c & 4)) return 1;
  if ((a & 1) && (c & 2) && (b & 4)) return 1;
  if ((b & 1) && (a & 2) && (c & 4)) return 1;
  if ((b & 1) && (c & 2) && (a & 4)) return 1;
  if ((c & 1) && (a & 2) && (b & 4)) return 1;
  if ((c & 1) && (b & 2) && (a & 4)) return 1;
  return 0;
}
int main() {
  scanf("%d", &t);
  for (int i = 1; i < 100010; i++)
    for (int j = i; j < 100010; j += i) di[j]++;
  while (t--) {
    scanf("%I64d%I64d%I64d", &x, &y, &z);
    init();
    for (int i = 1; i < 8; i++)
      for (int j = i; j < 8; j++)
        for (int k = j; k < 8; k++) {
          sum = 1;
          if (check(i, j, k)) {
            for (int l = 1; l < 8; l++) is[l] = 0;
            is[i]++;
            is[j]++;
            is[k]++;
            for (int l = 1; l < 8; l++)
              if (is[l]) sum = sum * Cnm(f[l] + is[l] - 1, is[l]);
            if (sum > 0) ans += sum;
          }
        }
    printf("%I64d\n", ans);
    ans = 0;
  }
}
