#include <bits/stdc++.h>
using namespace std;
const int N = 100000;
void into() {}
long long Get_d(int n) {
  long long res = 0;
  for (int i = 1; i * i <= n; ++i) {
    if (n % i) continue;
    ++res;
    if (i * i ^ n) ++res;
  }
  return res;
}
long long d[N + 9];
void Get_d() {
  for (int i = 1; i <= N; ++i) d[i] = Get_d(i);
}
void work() { Get_d(); }
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int gcd(int a, int b, int c) { return gcd(a, gcd(b, c)); }
void outo() {
  int cq;
  scanf("%d", &cq);
  for (; cq--;) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    long long ans = d[a] * d[b] * d[c];
    ans -= d[a] * d[gcd(b, c)] * (d[gcd(b, c)] - 1) / 2;
    ans -= d[b] * d[gcd(a, c)] * (d[gcd(a, c)] - 1) / 2;
    ans -= d[c] * d[gcd(a, b)] * (d[gcd(a, b)] - 1) / 2;
    ans +=
        2 * d[gcd(a, b, c)] * (d[gcd(a, b, c)] - 1) * (d[gcd(a, b, c)] - 2) / 3;
    ans +=
        d[gcd(a, b, c)] * (d[gcd(a, b, c)] - 1) *
        (d[gcd(a, b)] + d[gcd(b, c)] + d[gcd(a, c)] - 3 * d[gcd(a, b, c)] + 2) /
        2;
    ans -= (d[gcd(a, b)] - d[gcd(a, b, c)]) * (d[gcd(b, c)] - d[gcd(a, b, c)]) *
           (d[gcd(a, c)] - d[gcd(a, b, c)]);
    printf("%lld\n", ans);
  }
}
int main() {
  int T = 1;
  for (; T--;) {
    into();
    work();
    outo();
  }
  return 0;
}
