#include <bits/stdc++.h>
using namespace std;
int f[100010], aa, bb, cc;
int gc(int a, int b) {
  if (!b) return a;
  return gc(b, a % b);
}
int gc(int a, int b, int c) { return gc(a, gc(b, c)); }
int ff(int a, int b, int c) { return f[gc(a, b, c)]; }
int ff(int a, int b) { return f[gc(a, b)]; }
int g(int a, int b) { return ff(a, b) - ff(aa, bb, cc); }
int gg(int a, const int &b, const int &c) {
  return f[a] - ff(a, b) - ff(a, c) + ff(a, b, c);
}
long long C2(long long n) { return n * (n - 1) / 2; }
long long C3(long long n) { return n * (n - 1) * (n - 2) / 6; }
int main() {
  for (int i = 1; i < 100010; i++)
    for (int j = i; j < 100010; j += i) f[j]++;
  int T, a, b, c;
  cin >> T;
  while (T--) {
    scanf("%d%d%d", &a, &b, &c);
    aa = a, bb = b, cc = c;
    long long ans = 1ll * f[a] * f[b] * f[c];
    long long ct = ff(a, b, c) * (g(a, b) + g(b, c) + g(a, c));
    ans -= ct;
    ct = 2ll * C2(ff(a, b, c));
    ans -= 2ll * ct;
    ct = C3(ff(a, b, c));
    ans -= 5ll * ct;
    ct = C2(ff(a, b, c)) * (gg(a, b, c) + gg(b, a, c) + gg(c, a, b));
    ans -= ct;
    ct = C2(ff(a, b, c)) * (g(a, b) + g(a, c) + g(b, c));
    ans -= 3ll * ct;
    ct = ff(a, b, c) *
         (g(a, b) * g(a, c) + g(b, a) * g(b, c) + g(c, a) * g(c, b));
    ans -= 2ll * ct;
    ct = ff(a, b, c) * (g(a, b) * gg(c, a, b) + g(a, c) * gg(b, a, c) +
                        g(b, c) * gg(a, b, c));
    ans -= ct;
    ct = (C2(g(a, b)) * f[c] + C2(g(a, c)) * f[b] + C2(g(b, c)) * f[a]);
    ans -= ct;
    ct = g(a, b) * g(b, c) * g(a, c);
    ans -= ct;
    cout << ans << endl;
  }
  return 0;
}
