#include <bits/stdc++.h>
using namespace std;
const int Maxn = 100000;
const int inf = 2147483647;
int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9')
    x = (x << 3) + (x << 1) + (ch ^ 48), ch = getchar();
  return x * f;
}
int gcd(int a, int b) {
  if (!a) return b;
  return gcd(b % a, a);
}
int get(int x) {
  int re = 0;
  for (int i = 1; i * i <= x; i++)
    if (x % i == 0) {
      re++;
      if (i * i != x) re++;
    }
  return re;
}
int num[Maxn + 10];
int cnt[8], tot[8];
long long Combine[210][210];
bool check(int a, int b, int c) {
  if ((a & 1) && (b & 2) && (c & 4)) return true;
  if ((a & 1) && (c & 2) && (b & 4)) return true;
  if ((b & 1) && (a & 2) && (c & 4)) return true;
  if ((b & 1) && (c & 2) && (a & 4)) return true;
  if ((c & 1) && (a & 2) && (b & 4)) return true;
  if ((c & 1) && (b & 2) && (a & 4)) return true;
  return false;
}
int main() {
  for (int i = 1; i <= Maxn; i++) num[i] = get(i);
  Combine[0][0] = 1;
  for (int i = 1; i <= 200; i++) {
    Combine[i][0] = 1;
    for (int j = 1; j <= i; j++)
      Combine[i][j] = Combine[i - 1][j - 1] + Combine[i - 1][j];
  }
  int T = read();
  while (T--) {
    int x = read(), y = read(), z = read();
    long long A = num[x], B = num[y], C = num[z];
    long long AB = num[gcd(x, y)], BC = num[gcd(y, z)], AC = num[gcd(x, z)];
    long long ABC = num[gcd(gcd(x, y), z)];
    cnt[1] = A - AB - AC + ABC;
    cnt[2] = B - AB - BC + ABC;
    cnt[4] = C - AC - BC + ABC;
    cnt[3] = AB - ABC;
    cnt[5] = AC - ABC;
    cnt[6] = BC - ABC;
    cnt[7] = ABC;
    long long ans = 0;
    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)) {
            tot[1] = tot[2] = tot[3] = tot[4] = tot[5] = tot[6] = tot[7] = 0;
            tot[i]++, tot[j]++, tot[k]++;
            long long tmp = 1;
            for (int l = 1; l < 8; l++)
              if (tot[l]) tmp *= Combine[cnt[l] + tot[l] - 1][tot[l]];
            ans += tmp;
          }
    printf("%lld\n", ans);
  }
}
