#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int fac[N];
int cnt[10];
int use[10];
long long Count(int n, int m) {
  long long ret = 1;
  for (int i = 1; i <= m; i++) {
    ret *= (n - i + 1);
    ret /= i;
  }
  return ret;
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
bool get(int a, int b, int c) {
  if ((a & 4) && (b & 2) && (c & 1)) return true;
  if ((b & 4) && (a & 2) && (c & 1)) return true;
  if ((a & 4) && (c & 2) && (b & 1)) return true;
  if ((c & 4) && (a & 2) && (b & 1)) return true;
  if ((b & 4) && (c & 2) && (a & 1)) return true;
  if ((c & 4) && (b & 2) && (a & 1)) return true;
  return false;
}
void solve() {
  int A, B, C;
  scanf("%d%d%d", &A, &B, &C);
  int xy = gcd(A, B), xz = gcd(A, C), yz = gcd(B, C);
  int xyz = gcd(xy, C);
  memset(cnt, 0, sizeof(cnt));
  cnt[7] = fac[xyz];
  cnt[6] = fac[xy] - fac[xyz];
  cnt[5] = fac[xz] - fac[xyz];
  cnt[4] = fac[A] - fac[xy] - fac[xz] + fac[xyz];
  cnt[3] = fac[yz] - fac[xyz];
  cnt[2] = fac[B] - fac[xy] - fac[yz] + fac[xyz];
  cnt[1] = fac[C] - fac[xz] - fac[yz] + fac[xyz];
  long long ans = 0;
  for (int a = 1; a < 8; a++) {
    for (int b = a; b < 8; b++) {
      for (int c = b; c < 8; c++) {
        if (get(a, b, c)) {
          memset(use, 0, sizeof(use));
          use[a]++, use[b]++, use[c]++;
          long long tmp = 1;
          for (int i = 1; i < 8; i++) {
            if (use[i]) {
              tmp *= Count(cnt[i] + use[i] - 1, use[i]);
            }
          }
          ans += tmp;
        }
      }
    }
  }
  printf("%lld\n", ans);
}
int main() {
  memset(fac, 0, sizeof(fac));
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i) {
      fac[j]++;
    }
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    solve();
  }
  return 0;
}
