#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int fac[N];
void init() {
  for (int i = 1; i < N; i++)
    for (int j = i; j < N; j += i) fac[j]++;
  return;
}
long long C(int n, int m) {
  long long ans = 1;
  for (int i = 1; i <= m; i++) ans = ans * (n - i + 1) / i;
  return ans;
}
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
bool check(int a, int b, int c) {
  if ((a & 1) && (b & 2) && (c & 4)) return true;
  if ((a & 1) && (c & 2) && (b & 4)) return true;
  if ((b & 1) && (a & 2) && (c & 4)) return true;
  if ((b & 1) && (c & 2) && (a & 4)) return true;
  if ((c & 1) && (a & 2) && (b & 4)) return true;
  if ((c & 1) && (b & 2) && (a & 4)) return true;
  return false;
}
int f[10], use[10];
int main() {
  init();
  long long T;
  int x, y, z;
  long long ans;
  scanf("%lld", &T);
  while (T--) {
    scanf("%d%d%d", &x, &y, &z);
    int xy = gcd(x, y);
    int xz = gcd(x, z);
    int yz = gcd(y, z);
    int xyz = gcd(xy, z);
    f[1] = fac[x] - fac[xy] - fac[xz] + fac[xyz];
    f[2] = fac[y] - fac[xy] - fac[yz] + fac[xyz];
    f[4] = fac[z] - fac[xz] - fac[yz] + fac[xyz];
    f[3] = fac[xy] - fac[xyz];
    f[5] = fac[xz] - fac[xyz];
    f[6] = fac[yz] - fac[xyz];
    f[7] = fac[xyz];
    ans = 0;
    for (int a = 1; a < 8; a++)
      for (int b = a; b < 8; b++)
        for (int c = b; c < 8; c++)
          if (check(a, b, c) == true) {
            memset(use, 0, sizeof use);
            use[a]++;
            use[b]++;
            use[c]++;
            long long tmp = 1;
            for (int i = 1; i < 8; i++)
              if (use[i] != 0) tmp = tmp * C(f[i] + use[i] - 1, use[i]);
            if (tmp > 0) ans += tmp;
          }
    printf("%lld\n", ans);
  }
  return 0;
}
