#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
vector<vector<int>> divisorsAll(int n) {
  vector<vector<int>> res(n + 1);
  for (int i = 1; i <= n; ++i) {
    for (int j = i; j <= n; j += i) {
      res[j].push_back(i);
    }
  }
  return res;
}
int two(int n) { return n * (n + 1) / 2; }
int three(int n) { return n * (n + 1) * (n + 2) / 6; }
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(20);
  int T;
  cin >> T;
  auto D = divisorsAll(100005);
  vi E(100005);
  for (auto &(d) : (D)) sort((d).begin(), (d).end());
  int di[200 * 3] = {};
  int A[3];
  for (int(i) = (0); (i) < (int)(3); ++(i)) A[i] = i;
  while (T--) {
    int S[3];
    int m = 0;
    vi X(8), Y(8);
    for (int(i) = (0); (i) < (int)(3); ++(i)) {
      cin >> S[i];
      int a = S[i];
      for (auto &(d) : (D[a])) {
        E[d] |= 1 << i;
        di[m++] = d;
      }
    }
    sort(di, di + m);
    m = unique(di, di + m) - di;
    for (int(i) = (0); (i) < (int)(m); ++(i)) Y[E[di[i]]]++;
    int re = 0;
    for (int(i) = (0); (i) < (int)(8); ++(i))
      for (int(j) = (i + 1); (j) < (int)(8); ++(j)) {
        int ok = 0;
        do {
          if ((i >> A[0] & 1) && (i >> A[1] & 1) && (j >> A[2] & 1)) ok |= 1;
          if ((i >> A[0] & 1) && (j >> A[1] & 1) && (j >> A[2] & 1)) ok |= 2;
        } while (next_permutation(A, A + 3));
        if (ok & 1) re += two(Y[i]) * Y[j];
        if (ok & 2) re += Y[i] * two(Y[j]);
        for (int(k) = (j + 1); (k) < (int)(8); ++(k)) {
          ok = 0;
          do {
            if ((i >> A[0] & 1) && (j >> A[1] & 1) && (k >> A[2] & 1)) ok |= 1;
          } while (next_permutation(A, A + 3));
          if (ok) re += Y[i] * Y[j] * Y[k];
        }
      }
    re += three(Y[7]);
    cout << re << endl;
    for (int(i) = (0); (i) < (int)(m); ++(i)) E[di[i]] = 0;
  }
}
