#include <bits/stdc++.h>
using namespace std;
inline char gc() {
  static char buf[100000], *p1 = buf, *p2 = buf;
  return p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 100000, stdin), p1 == p2)
             ? EOF
             : *p1++;
}
inline long long read() {
  long long t = 0, f = 1;
  char anss = getchar();
  while (!isdigit(anss)) {
    if (anss == '-') f = -1;
    anss = getchar();
  }
  while (isdigit(anss)) t = t * 10 + anss - '0', anss = getchar();
  return t * f;
}
inline void write(long long x) {
  if (x < 0) {
    putchar('-');
    write(-x);
    return;
  }
  if (x >= 10) write(x / 10);
  putchar(x % 10 + '0');
}
inline void writeln(long long x) {
  write(x);
  puts("");
}
inline void write_p(long long x) {
  write(x);
  putchar(' ');
}
int n, a, b, c, cnt[200001], use[201], zt[200001], q[200001], top;
long long ans;
inline long long C(long long n, long long m) {
  if (!n) return 0;
  if (n < m) return 0;
  long long ans = 1;
  for (int i = n - m + 1; i <= n; ++i) ans *= i;
  for (int i = 1; i <= m; ++i) ans /= i;
  return ans;
}
int qq[200005];
inline bool Check(int x, int y, int z) {
  if (x & 1)
    if (y >> 1 & 1)
      if (z >> 2 & 1) return 1;
  return 0;
}
int main() {
  n = read();
  for (int T = 1; T <= n; ++T) {
    a = read();
    b = read();
    c = read();
    top = 0;
    int tmp = sqrt(a);
    for (int i = 1; i <= tmp; ++i)
      if (a % i == 0) {
        zt[i] += 1, q[++top] = i;
        if (i != a / i) zt[a / i] += 1, q[++top] = a / i;
      }
    tmp = sqrt(b);
    for (int i = 1; i <= tmp; ++i)
      if (b % i == 0) {
        zt[i] += 2, q[++top] = i;
        if (i != b / i) zt[b / i] += 2, q[++top] = b / i;
      }
    tmp = sqrt(c);
    for (int i = 1; i <= tmp; ++i)
      if (c % i == 0) {
        zt[i] += 4, q[++top] = i;
        if (i != c / i) zt[c / i] += 4, q[++top] = c / i;
      }
    sort(q + 1, q + top + 1);
    int ttop = 0;
    for (int i = 1; i <= top; ++i)
      if (q[i] != q[i - 1]) qq[++ttop] = q[i];
    top = ttop;
    for (int i = 1; i <= top; ++i) q[i] = qq[i];
    for (int i = 1; i <= 7; ++i) cnt[i] = 0;
    for (int i = 1; i <= top; ++i) cnt[zt[q[i]]]++;
    for (int i = 1; i <= 7; ++i)
      for (int j = i; j <= 7; ++j)
        for (int k = j; k <= 7; ++k) {
          long long tmp = 1;
          for (int t = 1; t <= 7; ++t) use[t] = 0;
          use[i]++;
          use[j]++;
          use[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))
            i = i;
          else
            continue;
          for (int t = 1; t <= 7; ++t)
            if (use[t]) tmp *= C(cnt[t] + use[t] - 1, use[t]);
          ans += tmp;
        }
    for (int i = 1; i <= top; ++i) zt[q[i]] = 0;
    top = 0;
    writeln(ans);
    ans = 0;
  }
}
