#include <bits/stdc++.h>
namespace IO {
char ch = '\n';
template <class T>
inline T ReadInt() {
  T x(0);
  bool f(1);
  while (ch < '0' || '9' < ch) {
    if (ch == '-') {
      f = 0;
    }
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return f ? x : -x;
}
template <class T>
inline T ReadUInt() {
  T x(0);
  while (ch < '0' || '9' < ch) {
    ch = getchar();
  }
  while ('0' <= ch && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return x;
}
inline double ReadDouble() {
  long long int_num = ReadInt<long long>();
  if (ch == '.') {
    double pow10 = 1, result = int_num;
    ch = getchar();
    while ('0' <= ch && ch <= '9') {
      pow10 /= 10.0;
      result += pow10 * (ch ^ 48);
      ch = getchar();
    }
    return result;
  } else {
    return (double)int_num;
  }
}
inline void ReadT(int &x) { x = ReadInt<int>(); }
inline void ReadT(long long &x) { x = ReadInt<long long>(); }
inline void ReadT(bool &x) { x = ReadUInt<bool>(); }
inline void ReadT(unsigned int &x) { x = ReadUInt<unsigned int>(); }
inline void ReadT(unsigned long long &x) { x = ReadUInt<unsigned long long>(); }
inline void ReadT(double &x) { x = ReadDouble(); }
inline void ReadT(char &s) {
  for (; isspace(ch) && (~ch); ch = getchar())
    ;
  s = ch;
  ch = '\n';
}
inline void ReadT(char *s) {
  int len(0);
  for (; isspace(ch) && (~ch); ch = getchar())
    ;
  for (; !isspace(ch) && (~ch); ch = getchar()) {
    s[len++] = ch;
  }
  s[len] = '\0';
  ch = '\n';
}
template <typename T>
inline void Read(T &t) {
  ReadT(t);
}
template <typename T, typename... Args>
void Read(T &t, Args &...args) {
  ReadT(t);
  Read(args...);
}
template <typename T>
void WriteInt(T x) {
  if (x < 0) {
    printf("-");
    x = -x;
  }
  if (9 < x) {
    WriteInt(x / 10);
  }
  putchar(x % 10 + '0');
}
template <typename T>
void WriteUInt(T x) {
  if (9 < x) {
    WriteInt(x / 10);
  }
  putchar(x % 10 + '0');
}
void WriteDouble(long double x, int len) {
  WriteInt((long long)x);
  if (len) {
    x -= (int)x;
    putchar('.');
    if (!x) {
      while (len--) {
        putchar(48);
      }
      return;
    }
    while (len--) {
      x *= 10;
    }
    WriteInt((long long)round(x));
  }
}
template <typename T>
inline void WriteT(T x);
template <>
inline void WriteT<int>(int x) {
  WriteInt<int>(x);
}
template <>
inline void WriteT<long long>(long long x) {
  WriteInt<long long>(x);
}
template <>
inline void WriteT<bool>(bool x) {
  WriteUInt<bool>(x);
}
template <>
inline void WriteT<unsigned int>(unsigned int x) {
  WriteUInt<unsigned int>(x);
}
template <>
inline void WriteT<unsigned long long>(unsigned long long x) {
  WriteUInt<unsigned long long>(x);
}
template <>
inline void WriteT<double>(double x) {
  WriteDouble(x, 6);
}
template <>
inline void WriteT<char *>(char *s) {
  int len(strlen(s));
  while (len--) {
    putchar(*s++);
  }
}
template <>
inline void WriteT<const char *>(const char *s) {
  while (*s) {
    putchar(*s++);
  }
}
template <>
inline void WriteT<char>(char x) {
  putchar(x);
}
template <typename T>
inline void Write(T t) {
  WriteT(t);
}
template <typename T, typename... Args>
void Write(T t, Args... args) {
  WriteT(t);
  Write(args...);
}
template <typename T>
inline void Writeln(T t) {
  WriteT(t);
  puts("");
}
template <typename T, typename... Args>
inline void Writeln(T t, Args... args) {
  WriteT(t);
  Write(args...);
  puts("");
}
inline void Writeln() { puts(""); }
const char NUMBER[36] = {'0', '1', '2', '3', '4', '5', '6', '7', '8',
                         '9', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H',
                         'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q',
                         'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
template <typename T>
void WriteK(T x, int p) {
  if (x < 0) {
    printf("-");
    x = -x;
  }
  if (p <= x) {
    WriteK(x / p, p);
  }
  putchar(NUMBER[x % p]);
}
}  // namespace IO
using namespace IO;
using namespace std;
const int MAX_NUM = 1e5 + 5;
const int MAXN = 1e5 + 5;
int a, b, c;
namespace Prime {
bool notprime[MAX_NUM];
int prime[MAX_NUM];
int sum[MAX_NUM];
int num[MAX_NUM];
int cnt = 0;
void Calc(int top) {
  sum[1] = 1;
  for (int i = 2; i <= top; ++i) {
    if (!notprime[i]) {
      sum[i] = 2;
      num[i] = 1;
      prime[++cnt] = i;
    }
    for (int j = 1; j <= cnt && i * prime[j] <= top; ++j) {
      notprime[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        sum[i * prime[j]] = sum[i] / (num[i] + 1) * (num[i] + 2);
        num[i * prime[j]] = num[i] + 1;
        break;
      } else {
        sum[i * prime[j]] = sum[i] << 1;
        num[i * prime[j]] = 1;
      }
    }
  }
}
}  // namespace Prime
long long Gcd(long long a, long long b) {
  if (!b) {
    return a;
  }
  return Gcd(b, a % b);
}
void Work() {
  Read(a, b, c);
  long long da = Prime::sum[a], db = Prime::sum[b], dc = Prime::sum[c],
            dab = Prime::sum[Gcd(a, b)], dbc = Prime::sum[Gcd(b, c)],
            dac = Prime::sum[Gcd(a, c)], dg = Prime::sum[Gcd(a, Gcd(b, c))];
  Writeln(da * db * dc - dab * (dab - 1) / 2 * dc - dbc * (dbc - 1) / 2 * da -
          dac * (dac - 1) / 2 * db + 4 * dg * (dg - 1) * (dg - 2) / 6 +
          2 * dg * (dg - 1) / 2 +
          dg * (dg - 1) * (dab + dbc + dac - 3 * dg) / 2 -
          (dab - dg) * (dbc - dg) * (dac - dg));
}
int main() {
  Prime::Calc(100000);
  int t;
  Read(t);
  for (int i = 1; i <= t; ++i) {
    Work();
  }
  return 0;
}
