#include <bits/stdc++.h>
using namespace std;
const int INF = 0x3f3f3f3f;
const int N = 100000 + 111;
int fac[N];
int sum[10], cnt[10];
long long Comb(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) && (b & 4) && (c & 2)) return true;
  if ((a & 2) && (b & 1) && (c & 4)) return true;
  if ((a & 2) && (b & 4) && (c & 1)) return true;
  if ((a & 4) && (b & 1) && (c & 2)) return true;
  if ((a & 4) && (b & 2) && (c & 1)) return true;
  return false;
}
int main() {
  int a, b, c, A, B, C, i, j, k, h, ac, ab, bc, abc, t;
  long long ans;
  scanf("%d", &t);
  for (i = 1; i <= N; i++)
    for (j = i; j <= N; j += i) fac[j]++;
  while (t--) {
    scanf("%d%d%d", &A, &B, &C);
    a = A;
    b = B;
    c = C;
    ac = gcd(A, C);
    bc = gcd(B, C);
    ab = gcd(A, B);
    abc = gcd(ab, C);
    sum[1] = fac[a] - fac[ab] - fac[ac] + fac[abc];
    sum[2] = fac[b] - fac[ab] - fac[bc] + fac[abc];
    sum[4] = fac[c] - fac[ac] - fac[bc] + fac[abc];
    sum[3] = fac[ab] - fac[abc];
    sum[6] = fac[bc] - fac[abc];
    sum[5] = fac[ac] - fac[abc];
    sum[7] = fac[abc];
    ans = 0;
    for (i = 1; i < 8; i++)
      for (j = i; j < 8; j++)
        for (k = j; k < 8; k++)
          if (check(i, j, k)) {
            memset(cnt, 0, sizeof(cnt));
            cnt[i]++;
            cnt[j]++;
            cnt[k]++;
            long long temp = 1;
            for (h = 1; h < 8; h++) {
              if (cnt[h]) {
                temp *= Comb(sum[h] + cnt[h] - 1, cnt[h]);
              }
            }
            if (temp > 0) ans += temp;
          }
    printf("%lld\n", ans);
  }
}
