#include <bits/stdc++.h>
using namespace std;
int T;
long long A, B, C, a, b, c;
long long f[100005], num[100005];
long long ans;
int isprime[100005], primes[100005], tot;
void init() {
  memset(f, 0, sizeof(f));
  f[1] = 1;
  for (int i = 2; i <= 100000; i++) {
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        f[i]++;
        if (j * j != i) f[i]++;
      }
    }
  }
}
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
int main() {
  cin >> T;
  init();
  tot = 0;
  while (T--) {
    cin >> a >> b >> c;
    int gabc = gcd(a, gcd(b, c));
    int gab = gcd(a, b);
    int gac = gcd(a, c);
    int gbc = gcd(b, c);
    ans = f[a] * f[b] * f[c];
    ans -= f[gab] * (f[gab] - 1ll) / 2ll * f[c] +
           f[gac] * (f[gac] - 1ll) / 2ll * f[b] +
           f[gbc] * (f[gbc] - 1) / 2ll * f[a];
    ans += f[gabc] * (f[gabc] - 1ll);
    ans += f[gabc] * (f[gabc] - 1ll) * (f[gabc] - 2ll) / 6ll * 4ll;
    ans += (f[gab] - f[gabc]) * f[gabc] * (f[gabc] - 1ll) / 2ll +
           (f[gac] - f[gabc]) * f[gabc] * (f[gabc] - 1ll) / 2ll +
           (f[gbc] - f[gabc]) * f[gabc] * (f[gabc] - 1ll) / 2ll;
    ans -= (f[gab] - f[gabc]) * (f[gbc] - f[gabc]) * (f[gac] - f[gabc]);
    cout << ans << endl;
  }
  return 0;
}
