#include <bits/stdc++.h>
const int MAXN = 100001;
int t, a, b, c, zc = 0;
long long zs[MAXN], d[MAXN] = {0, 1}, eb[MAXN];
bool hs[MAXN];
int Gcd(int u, int v) { return v ? Gcd(v, u % v) : u; }
inline long long Qjy(long long u) { return u * (u - 1); }
int main() {
  for (int i = 2; i <= MAXN; ++i) {
    if (!hs[i]) zs[++zc] = i, d[i] = 2, eb[i] = 1;
    for (int j = 1, cr; j <= zc && (cr = i * zs[j]) < MAXN; ++j) {
      hs[cr] = 1;
      if (!(i % zs[j])) {
        d[cr] = d[i] / (eb[i] + 1) * (eb[i] + 2), eb[cr] = eb[i] + 1;
        break;
      } else
        d[cr] = d[i] << 1, eb[cr] = 1;
    }
  }
  scanf("%d", &t);
  while (t-- && scanf("%d%d%d", &a, &b, &c) != EOF) {
    int ga = Gcd(b, c), gb = Gcd(a, c), gc = Gcd(a, b);
    int gg = Gcd(a, ga);
    printf(
        "%lld\n",
        d[a] * d[b] * d[c] -
            (d[a] * Qjy(d[ga]) + d[b] * Qjy(d[gb]) + d[c] * Qjy(d[gc]) >> 1) +
            (Qjy(d[gg]) * (d[gg] - 2) / 3 << 1) +
            (Qjy(d[gg]) * (d[ga] + d[gb] + d[gc] - 3 * d[gg] + 2) >> 1) -
            (d[ga] - d[gg]) * (d[gb] - d[gg]) * (d[gc] - d[gg]));
  }
  return 0;
}
