#include <bits/stdc++.h>
inline int readInt() {
  int ans = 0, c, f = 1;
  while (!isdigit(c = getchar()))
    if (c == '-') f *= -1;
  do ans = ans * 10 + c - '0';
  while (isdigit(c = getchar()));
  return ans * f;
}
int gcd(int a, int b) {
  while (b) std::swap(a %= b, b);
  return a;
}
const int N = 100050;
const int A[6][3] = {{0, 1, 2}, {0, 2, 1}, {1, 0, 2},
                     {1, 2, 0}, {2, 0, 1}, {2, 1, 0}};
int d[N], k[64];
int C[64][3], m[64];
int KK[8];
int main() {
  for (int i = 1; i < N; ++i)
    for (int j = i; j < N; j += i) ++d[j];
  k[0] = -1;
  for (int i = 0; i < 6; ++i) m[1 << i] = i;
  for (int S = 1; S < 64; ++S) k[S] = -k[S & (S - 1)], m[S] = m[S & -S];
  int t = readInt();
  while (t--) {
    int B[3];
    B[0] = readInt();
    B[1] = readInt();
    B[2] = readInt();
    for (int S = 1; S < 8; ++S) KK[S] = gcd(KK[S & (S - 1)], B[m[S]]);
    for (int S = 1; S < 8; ++S) KK[S] = d[KK[S]];
    long long ans = 0;
    for (int S = 1; S < 64; ++S) {
      C[S][0] = C[S & (S - 1)][0] | (1 << A[m[S]][0]);
      C[S][1] = C[S & (S - 1)][1] | (1 << A[m[S]][1]);
      C[S][2] = C[S & (S - 1)][2] | (1 << A[m[S]][2]);
      ans += (long long)k[S] * KK[C[S][0]] * KK[C[S][1]] * KK[C[S][2]];
      ans += (long long)k[S] * KK[C[S][0] | C[S][1]] * KK[C[S][2]];
      ans += (long long)k[S] * KK[C[S][0] | C[S][2]] * KK[C[S][1]];
      ans += (long long)k[S] * KK[C[S][1] | C[S][2]] * KK[C[S][0]];
    }
    ans += (long long)2 * d[gcd(gcd(B[0], B[1]), B[2])];
    printf("%I64d\n", ans / 6);
  }
}
