#include <bits/stdc++.h>
using namespace std;
const int MAXN = 100005;
inline long long C(int n, int m) {
  long long ret = 1;
  for (register int i = 1; i <= m; ++i) ret = ret * (n - i + 1) / i;
  return ret;
}
inline bool check(int a, int b, int c) {
  if ((a & 1) && (b & 2) && (c & 4)) return 1;
  if ((a & 1) && (c & 2) && (b & 4)) return 1;
  if ((b & 1) && (a & 2) && (c & 4)) return 1;
  if ((b & 1) && (c & 2) && (a & 4)) return 1;
  if ((c & 1) && (a & 2) && (b & 4)) return 1;
  if ((c & 1) && (b & 2) && (a & 4)) return 1;
  return 0;
}
inline int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
int n;
int q[MAXN], m;
int cnt[10], use[10];
int fac[MAXN];
inline void init(int n) {
  for (register int i = 1; i <= n; ++i)
    for (register int j = i; j <= n; j += i) ++fac[j];
}
int main() {
  init(1e5);
  int T, X, Y, Z;
  scanf("%d", &T);
  long long ans;
  while (T--) {
    scanf("%d%d%d", &X, &Y, &Z);
    m = 0;
    int xy = gcd(X, Y), yz = gcd(Y, Z), xz = gcd(X, Z);
    int xyz = gcd(xy, Z);
    cnt[7] = fac[xyz];
    cnt[6] = fac[yz] - fac[xyz];
    cnt[5] = fac[xz] - fac[xyz];
    cnt[4] = fac[Z] - fac[xz] - fac[yz] + fac[xyz];
    cnt[3] = fac[xy] - fac[xyz];
    cnt[2] = fac[Y] - fac[yz] - fac[xy] + fac[xyz];
    cnt[1] = fac[X] - fac[xy] - fac[xz] + fac[xyz];
    ans = 0;
    for (register int a = 1; a < 8; ++a)
      for (register int b = a; b < 8; ++b)
        for (register int c = b; c < 8; ++c)
          if (check(a, b, c)) {
            memset(use, 0, sizeof use);
            ++use[a];
            ++use[b];
            ++use[c];
            long long tmp = 1;
            for (register int i = 1; i <= 7; ++i)
              if (use[i]) tmp *= C(cnt[i] + use[i] - 1, use[i]);
            if (tmp > 0) ans += tmp;
          }
    printf("%lld\n", ans);
  }
  return 0;
}
