#include <bits/stdc++.h>
using namespace std;
char buf[25];
struct node {
  int a, b, c;
} q[1010];
int f[100010];
int g[8], cnt[8];
int n;
int read() {
  int x = 0, f = 0;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch ^ 48);
    ch = getchar();
  }
  return f ? -x : x;
}
void write(int x) {
  if (!x) {
    putchar('0');
    return;
  }
  if (x < 0) {
    putchar('-');
    x = -x;
  }
  int cnt = 0;
  while (x) {
    buf[++cnt] = '0' + x % 10;
    x /= 10;
  }
  for (int i = cnt; i >= 1; --i) putchar(buf[i]);
}
bool ck(int x, int y, int z) {
  if ((x & 1) && (y & 2) && (z & 4)) return true;
  if ((x & 1) && (y & 4) && (z & 2)) return true;
  if ((x & 2) && (y & 1) && (z & 4)) return true;
  if ((x & 2) && (y & 4) && (z & 1)) return true;
  if ((x & 4) && (y & 1) && (z & 2)) return true;
  if ((x & 4) && (y & 2) && (z & 1)) return true;
  return false;
}
void init() {
  for (int i = 1; i <= 100000; ++i) {
    for (int j = 1; j <= sqrt(i); ++j)
      if (i % j == 0) {
        ++f[i];
        if (i / j != j) ++f[i];
      }
  }
  for (int i = 0; i <= 7; ++i)
    for (int j = i; j <= 7; ++j)
      for (int k = j; k <= 7; ++k)
        if (ck(i, j, k)) {
          q[++n] = (node){i, j, k};
        }
}
int gcd(int x, int y) {
  int z = x % y;
  while (z) {
    x = y;
    y = z;
    z = x % y;
  }
  return y;
}
int C(int x, int y) {
  if (x < y) return 0;
  if (y == 1) return x;
  if (y == 2) return x * (x - 1) / 2;
  if (y == 3) return x * (x - 1) * (x - 2) / 6;
}
void solve() {
  int a, b, c, ab, ac, bc, abc;
  a = read();
  b = read();
  c = read();
  ab = gcd(a, b);
  ac = gcd(a, c);
  bc = gcd(b, c);
  abc = gcd(gcd(a, b), c);
  g[0] = 0;
  g[1] = f[a] - f[ab] - f[ac] + f[abc];
  g[2] = f[b] - f[ab] - f[bc] + f[abc];
  g[3] = f[ab] - f[abc];
  g[4] = f[c] - f[ac] - f[bc] + f[abc];
  g[5] = f[ac] - f[abc];
  g[6] = f[bc] - f[abc];
  g[7] = f[abc];
  int ans = 0;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= 7; ++j) cnt[j] = 0;
    ++cnt[q[i].a];
    ++cnt[q[i].b];
    ++cnt[q[i].c];
    int tmp = 1;
    for (int j = 0; j <= 7; ++j)
      if (cnt[j]) tmp *= C(g[j] + cnt[j] - 1, cnt[j]);
    ans += tmp;
  }
  write(ans);
  putchar('\n');
}
int main() {
  init();
  int t = read();
  while (t--) solve();
  return 0;
}
