#include <bits/stdc++.h>
using namespace std;
template <class T>
bool uin(T &a, T b) {
  return a > b ? (a = b, true) : false;
}
template <class T>
bool uax(T &a, T b) {
  return a < b ? (a = b, true) : false;
}
int const mm = 1e5 + 100;
vector<int> d[mm];
int f[8];
void solve() {
  int a, b, c;
  cin >> a >> b >> c;
  vector<int> r, rab;
  merge((d[a]).begin(), (d[a]).end(), (d[b]).begin(), (d[b]).end(),
        back_inserter(rab));
  merge((rab).begin(), (rab).end(), (d[c]).begin(), (d[c]).end(),
        back_inserter(r));
  r.erase(unique((r).begin(), (r).end()), r.end());
  memset(f, 0, sizeof f);
  for (auto i : r) {
    int p = 0;
    if (a % i == 0) p += 1;
    if (b % i == 0) p += 2;
    if (c % i == 0) p += 4;
    f[p]++;
  }
  long long an = 0;
  for (int i = 1; i < 8; i++) {
    for (int j = i; j < 8; j++) {
      for (int k = j; k < 8; k++) {
        if ((i | j | k) != 7) continue;
        if ((i == j || j == k) && (j == 1 || j == 2 || j == 4)) continue;
        int z = f[j];
        if (i == j && j == k) {
          an += z * (z + 1) * (z + 2) / 6;
          continue;
        }
        if (i == j) {
          an += z * (z + 1) * f[k] / 2;
          continue;
        }
        if (j == k) {
          an += z * (z + 1) * f[i] / 2;
          continue;
        }
        an += f[i] * f[j] * f[k];
      }
    }
  }
  cout << an << endl;
  return;
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.tie(nullptr);
  cout.precision(10);
  cout << fixed;
  for (int i = 1; i < mm; i++)
    for (int j = i; j < mm; j += i) d[j].push_back(i);
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
