#include <bits/stdc++.h>
using namespace std;
const int N = 100001;
int A, B, C, f[N], fg[N], pri[N], cnt, e[N];
long long ans;
void pre(int Maxn) {
  f[1] = 1;
  for (int i = 2; i <= Maxn; i++) {
    if (!fg[i]) f[pri[++cnt] = i] = 2, e[i] = 1;
    for (int j = 1; j <= cnt && i * pri[j] <= Maxn; j++) {
      int t = i * pri[j];
      fg[t] = 1;
      if (i % pri[j] == 0) {
        e[t] = e[i] + 1;
        f[t] = f[i] / e[t] * (e[t] + 1);
        break;
      }
      e[t] = 1;
      f[t] = f[i] << 1;
    }
  }
}
int gcd(int a, int b) { return !b ? a : gcd(b, a % b); }
void solve(int a, int b, int c) {
  int Gab = gcd(a, b), Gac = gcd(a, c), Gbc = gcd(b, c), Gabc = gcd(Gab, Gbc);
  int t = f[Gabc];
  int tab = f[Gab] - f[Gabc], tbc = f[Gbc] - f[Gabc], tac = f[Gac] - f[Gabc];
  int Ta = f[a] - f[Gab] - f[Gac] + f[Gabc],
      Tb = f[b] - f[Gbc] - f[Gab] + f[Gabc],
      Tc = f[c] - f[Gac] - f[Gbc] + f[Gabc];
  ans += 1ll * t * (t - 1) * (t - 2) / 6 + 1ll * t * (t - 1) + 1ll * t;
  ans += 1ll * (1ll * t * (t - 1) / 2 + t) * (tab + tbc + tac);
  ans += 1ll * (1ll * t * (t - 1) / 2 + t) * (Ta + Tb + Tc);
  ans += 1ll * t *
         (1ll * tab * tbc + 1ll * tab * tac + 1ll * tbc * tac +
          1ll * tab * (tab - 1) / 2 + tab + 1ll * tbc * (tbc - 1) / 2 + tbc +
          1ll * tac * (tac - 1) / 2 + tac);
  ans += 1ll * t * (tab + tbc + tac) * (Ta + Tb + Tc);
  ans += 1ll * t * (Ta * Tb + Ta * Tc + Tb * Tc);
  ans += 1ll * tab * tbc * tac +
         (1ll * tab * (tab - 1) / 2 + tab) * (tac + tbc) +
         (1ll * tbc * (tbc - 1) / 2 + tbc) * (tab + tac) +
         (1ll * tac * (tac - 1) / 2 + tac) * (tab + tbc);
  ans += (1ll * tab * (tab - 1) / 2 + tab + 1ll * tac * tbc +
          1ll * tab * (tbc + tac)) *
             Tc +
         (1ll * tbc * (tbc - 1) / 2 + tbc + 1ll * tac * tab +
          1ll * tbc * (tab + tac)) *
             Ta +
         (1ll * tac * (tac - 1) / 2 + 1ll * tac + tbc * tab +
          1ll * tac * (tab + tbc)) *
             Tb;
  ans += (1ll * Ta * Tb * (tac + tbc) + 1ll * Tb * Tc * (tab + tac) +
          1ll * Ta * Tc * (tab + tbc));
  ans += 1ll * Ta * Tb * Tc;
}
int main() {
  pre(100000);
  int T;
  scanf("%d", &T);
  while (T--) {
    scanf("%d%d%d", &A, &B, &C);
    ans = 0;
    solve(A, B, C);
    cout << ans << endl;
  }
  return 0;
}
