#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 10;
int t, sz_used, used[MAXN], cnt_used[MAXN], used_by[3][MAXN];
long long k2, k3, k[3][3], u[3];
void init() {
  for (int i = 0; i < sz_used; ++i) cnt_used[used[i]] = 0;
  sz_used = k2 = k3 = 0;
  for (int i = 0; i < 3; ++i) {
    u[i] = 0;
    for (int j = 0; j < 3; ++j) k[i][j] = 0;
  }
}
void add(int i, int id) {
  if (cnt_used[i] == 0) used[sz_used++] = i;
  used_by[cnt_used[i]++][i] = id;
}
void update_used(int n, int id) {
  for (int i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      add(i, id);
      if (i * i != n) add(n / i, id);
    }
  }
}
void update_cnt() {
  for (int i = 0, num, cnt; i < sz_used; ++i) {
    num = used[i];
    cnt = cnt_used[num];
    if (cnt == 1)
      ++u[used_by[0][num]];
    else if (cnt == 2) {
      ++k[used_by[0][num]][used_by[1][num]];
      ++k[used_by[1][num]][used_by[0][num]];
      ++k2;
    } else
      ++k3;
  }
}
long long comb2(long long x) { return (x * (x - 1LL)) >> 1; }
long long comb3(long long x) { return (x * (x - 1) * (x - 2)) / 6; }
long long solve() {
  update_cnt();
  return k3 + comb3(k3) + k3 * (k3 - 1) + k2 * k3 + k3 * comb2(k2) + k2 * k3 +
         k2 * comb2(k3) +
         ((k[0][1] * k[0][2] + k[0][1] * k[1][2] + k[0][2] * k[1][2]) << 1) +
         comb2(k[0][1]) * (k[0][2] + k[1][2]) +
         comb2(k[0][2]) * (k[0][1] + k[1][2]) +
         comb2(k[1][2]) * (k[0][1] + k[0][2]) + k[0][1] * k[0][2] * k[1][2] +
         u[0] * u[1] * u[2] + u[0] * k[1][2] + u[1] * k[0][2] + u[2] * k[0][1] +
         (u[0] + u[1] + u[2]) *
             (k[0][1] * k[0][2] + k[0][1] * k[1][2] + k[0][2] * k[1][2]) +
         u[0] * comb2(k[1][2]) + u[1] * comb2(k[0][2]) + u[2] * comb2(k[0][1]) +
         u[0] * u[1] * (k[0][2] + k[1][2]) + u[0] * u[2] * (k[0][1] + k[1][2]) +
         u[1] * u[2] * (k[0][1] + k[0][2]) + (u[0] + u[1] + u[2]) * k3 +
         (u[0] + u[1] + u[2]) * comb2(k3) +
         (u[0] * u[1] + u[0] * u[2] + u[1] * u[2]) * k3 +
         u[0] * k3 * (k[1][0] + k[1][2] + k[2][0]) +
         u[1] * k3 * (k[0][1] + k[0][2] + k[2][1]) +
         u[2] * k3 * (k[0][1] + k[0][2] + k[1][2]);
}
int main() {
  scanf("%d", &t);
  while (t--) {
    init();
    for (int i = 0, n; i < 3; ++i) {
      scanf("%d", &n);
      update_used(n, i);
    }
    printf("%ld\n", solve());
  }
  return 0;
}
