#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
const int a = 1;
const int b = 2;
const int c = 3;
const int ab = 4;
const int bc = 5;
const int ac = 6;
const int abc = 7;
long long cnt[maxn], numb[10];
int store[10];
vector<int> va, vb, vc;
set<long long> st;
void init() {
  for (int i = 1; i < maxn; ++i)
    for (int j = i; j < maxn; j += i) cnt[j] += 1;
  va.push_back(a);
  va.push_back(ab);
  va.push_back(ac);
  va.push_back(abc);
  vb.push_back(b);
  vb.push_back(bc);
  vb.push_back(ab);
  vb.push_back(abc);
  vc.push_back(c);
  vc.push_back(ac);
  vc.push_back(bc);
  vc.push_back(abc);
}
long long cal2(long long x) { return x + x * (x - 1) / 2; }
long long cal3(long long x) {
  return x + x * (x - 1) + x * (x - 1) * (x - 2) / 6;
}
long long gcd(long long a, long long b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  init();
  long long T, A, B, C;
  scanf("%lld", &T);
  while (T--) {
    st.clear();
    scanf("%lld%lld%lld", &A, &B, &C);
    long long dab = gcd(A, B), dbc = gcd(B, C), dac = gcd(A, C),
              dabc = gcd(dab, C);
    numb[abc] = cnt[dabc];
    numb[ab] = cnt[dab] - numb[abc], numb[bc] = cnt[dbc] - numb[abc],
    numb[ac] = cnt[dac] - numb[abc];
    numb[a] = cnt[A] - numb[ab] - numb[ac] - numb[abc];
    numb[b] = cnt[B] - numb[ab] - numb[bc] - numb[abc];
    numb[c] = cnt[C] - numb[ac] - numb[bc] - numb[abc];
    long long ans = 0;
    for (int i = 0; i < va.size(); ++i) {
      for (int j = 0; j < vb.size(); ++j) {
        for (int k = 0; k < vc.size(); ++k) {
          store[0] = va[i], store[1] = vb[j], store[2] = vc[k];
          sort(store, store + 3);
          long long hash = 0;
          for (int u = 0; u < 3; ++u) hash = hash * 10 + store[u];
          if (st.count(hash)) continue;
          st.insert(hash);
          int one = store[0], two = store[1], three = store[2];
          if (one == two && two == three) {
            ans += cal3(numb[one]);
          } else if (one == two) {
            ans += numb[three] * cal2(numb[one]);
          } else if (two == three) {
            ans += numb[one] * cal2(numb[two]);
          } else if (one == three) {
            ans += numb[two] * cal2(numb[one]);
          } else {
            ans += numb[one] * numb[two] * numb[three];
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
