#include <bits/stdc++.h>
using namespace std;
const int inf = 0x7fffffff;
const double eps = 1e-10;
const double pi = acos(-1.0);
inline int read() {
  int x = 0, f = 1;
  char ch;
  ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = 0;
    ch = getchar();
  }
  while (ch >= '0' && ch <= '9') {
    x = (x << 1) + (x << 3) + (ch & 15);
    ch = getchar();
  }
  if (f)
    return x;
  else
    return -x;
}
const int N = 1e5 + 10;
int a, b, c;
bool vis[N];
int pri[N], cnt[N], power[N];
int prime[N], S[N];
void Get_Shai(int n) {
  S[1] = 1;
  for (int i = 1; i <= n; i++) power[i] = 1;
  for (int i = 2; i <= n; i++) {
    if (!vis[i]) {
      cnt[i] = 1;
      pri[i] = i;
      power[i] = i;
      prime[++prime[0]] = i;
      S[i] = 2;
    }
    for (int j = 1, v, pc; j <= prime[0] && i * prime[j] <= n; j++) {
      v = i * prime[j];
      vis[v] = 1;
      if (i % prime[j] == 0) {
        cnt[v] = cnt[i] + 1;
        pri[v] = pri[i];
        power[v] = power[i] * pri[i];
        S[v] = S[v / power[v]] * (cnt[v] + 1);
        break;
      }
      cnt[v] = 1;
      pri[v] = prime[j];
      power[v] = prime[j];
      S[v] = S[i] * 2;
    }
  }
}
long long num[8];
int op[4], x, y, z;
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long cal3(long long x) {
  return x + x * (x - 1) + x * (x - 1) * (x - 2) / 6;
}
long long cal2(long long x) { return x + x * (x - 1) / 2; }
map<int, bool> mp;
int va[4] = {0, 3, 5, 6};
int vb[4] = {1, 3, 4, 6};
int vc[4] = {2, 5, 4, 6};
int main() {
  Get_Shai(N - 10);
  int T = read();
  while (T--) {
    a = read();
    b = read();
    c = read();
    int ab = gcd(a, b), bc = gcd(b, c), ac = gcd(a, c), abc = gcd(a, bc);
    num[6] = S[abc];
    num[3] = S[ab] - num[6], num[4] = S[bc] - num[6], num[5] = S[ac] - num[6];
    num[0] = S[a] - num[3] - num[5] - num[6];
    num[1] = S[b] - num[3] - num[4] - num[6];
    num[2] = S[c] - num[5] - num[4] - num[6];
    mp.clear();
    long long ans = 0;
    for (int i = 0; i < 4; i++)
      for (int j = 0; j < 4; j++)
        for (int k = 0; k < 4; k++) {
          op[0] = va[i], op[1] = vb[j], op[2] = vc[k];
          sort(op, op + 3);
          x = op[0], y = op[1], z = op[2];
          if (mp[(x << 8) + (y << 4) + z]) continue;
          mp[(x << 8) + (y << 4) + z] = 1;
          if (x == y && y == z)
            ans += cal3(num[x]);
          else if (x == y)
            ans += num[z] * cal2(num[x]);
          else if (y == z)
            ans += num[x] * cal2(num[y]);
          else if (z == x)
            ans += num[y] * cal2(num[z]);
          else
            ans += num[x] * num[y] * num[z];
        }
    printf("%I64d\n", ans);
  }
  return 0;
}
