#include <bits/stdc++.h>
const int K = 3, S = 55, MAX = 100001;
std::vector<int> fact[MAX];
void cmin(int& a, int b) { b < a ? a = b : 1; }
int pc[1 << K], st[S][K], sc;
void dfs(int i) {
  if (i == K) {
    for (i = 0; i < K; i++) st[sc + 1][i] = st[sc][i];
    sc++;
    return;
  }
  for (int x = i ? st[sc][i - 1] : 1; x < 1 << K; x++) {
    bool fl = 1;
    for (int s = 0; s < 1 << i && fl; s++) {
      int u = x;
      for (int j = 0; j < i; j++)
        if (s >> j & 1) u |= st[sc][j];
      if (pc[u] <= pc[s]) fl = 0;
    }
    if (fl) st[sc][i] = x, dfs(i + 1);
  }
}
int A[K], cnt[1 << K];
int main() {
  int t;
  scanf("%d", &t);
  for (int i = 1; i < MAX; i++)
    for (int j = i; j < MAX; j += i) fact[j].push_back(i);
  for (int i = 1; i < 1 << K; i++) pc[i] = pc[i & i - 1] + 1;
  dfs(0);
  while (t--) {
    for (int i = 0; i < K; i++) scanf("%d", A + i);
    for (int i = 0; i < 1 << K; i++) cnt[i] = 0;
    int pos[3] = {0}, ans = 0;
    for (;;) {
      int x = MAX, y = 0;
      for (int i = 0; i < K; i++)
        if (pos[i] < fact[A[i]].size()) cmin(x, fact[A[i]][pos[i]]);
      if (x == MAX) break;
      for (int i = 0; i < K; i++)
        if (pos[i] < fact[A[i]].size() && fact[A[i]][pos[i]] == x)
          y |= 1 << i, pos[i]++;
      cnt[y]++;
    }
    for (int i = 0; i < sc; i++) {
      int *s = st[i], w = 1, c = 0;
      for (int j = 0; j < K; j++)
        c = j && s[j] == s[j - 1] ? c + 1 : 0,
        w = w * (cnt[s[j]] + c) / (c + 1);
      ans += w;
    }
    printf("%d\n", ans);
  }
}
