#include <bits/stdc++.h>
using namespace std;
const int maxn = 100000;
int te, A, B, C, num[maxn + 5], AB, AC, BC, ABC, sum[8];
long long ans;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline bool check(int i, int j, int k) { return (i & 1) && (j & 2) && (k & 4); }
inline long long C3(long long x) { return x * (x - 1) * (x - 2) / 6; }
inline long long C2(long long x) { return x * (x - 1) / 2; }
int main() {
  for (int i = 1; i <= maxn; i++)
    for (int j = i; j <= maxn; j += i) num[j]++;
  for (scanf("%d", &te); te; printf("%lld\n", ans), ans = 0, te--) {
    scanf("%d%d%d", &A, &B, &C);
    AB = gcd(A, B);
    AC = gcd(A, C);
    BC = gcd(B, C);
    ABC = gcd(AB, C);
    sum[1] = num[A] - num[AB] - num[AC] + num[ABC];
    sum[2] = num[B] - num[AB] - num[BC] + num[ABC];
    sum[3] = num[AB] - num[ABC];
    sum[4] = num[C] - num[AC] - num[BC] + num[ABC];
    sum[5] = num[AC] - num[ABC];
    sum[6] = num[BC] - num[ABC];
    sum[7] = num[ABC];
    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) || check(i, k, j) || check(j, i, k) ||
              check(j, k, i) || check(k, i, j) || check(k, j, i))
            if (i == j && j == k)
              ans += C3(sum[i] + 2);
            else if (i == j)
              ans += C2(sum[i] + 1) * sum[k];
            else if (j == k)
              ans += C2(sum[j] + 1) * sum[i];
            else
              ans += (long long)sum[i] * sum[j] * sum[k];
  }
  return 0;
}
