#include <bits/stdc++.h>
using namespace std;
template <class TH>
void _dbg(const char *sdbg, TH h) {
  cerr << sdbg << " = " << h << endl;
}
template <class TH, class... TA>
void _dbg(const char *sdbg, TH h, TA... a) {
  while (*sdbg != ',') cerr << *sdbg++;
  cerr << " = " << h << ", ";
  _dbg(sdbg + 1, a...);
}
const int maxn = (1e5) + 7;
const int maxk = 20;
const int inf = (1e9) + 7;
const long long LLinf = (1e18) + 7;
const long double eps = 1e-9;
const long long mod = 1e9 + 7;
long long ile[maxn];
vector<int> dziel[maxn];
long long res = 0;
long long tab[10];
long long dp[100];
vector<vector<int> > P;
bool dziala(int a, int b, int c) {
  vector<int> V;
  V.push_back(1);
  V.push_back(2);
  V.push_back(4);
  do {
    if ((a & V[0]) && (b & V[1]) && (c & V[2])) return 1;
  } while (next_permutation(V.begin(), V.end()));
  return 0;
}
long long po3(long long a) { return a * (a - 1) * (a - 2) / 6LL; }
long long po2(long long a) { return a * (a - 1) / 2LL; }
void solve() {
  res = 0;
  vector<int> G, V;
  cin >> tab[0] >> tab[1] >> tab[2];
  vector<int> a[3];
  a[0] = dziel[tab[0]];
  a[1] = dziel[tab[1]];
  a[2] = dziel[tab[2]];
  while (((int)(a[0]).size()) + ((int)(a[1]).size()) + ((int)(a[2]).size()) >
         0) {
    int kand = 0;
    int kto = 0;
    for (int i = 0; i < 3; i++)
      if (((int)(a[i]).size())) kand = max(kand, a[i].back());
    G.push_back(kand);
    for (int i = 0; i < 3; i++)
      while (((int)(a[i]).size()) && a[i].back() == kand) a[i].pop_back();
  }
  for (int i = 0; i < 10; i++) dp[i] = 0LL;
  for (auto s : G) {
    int mask = 0;
    for (int j = 0; j < 3; j++)
      if (tab[j] % s == 0) mask |= (1 << j);
    dp[mask]++;
  }
  long long res = 0LL;
  for (auto s : P) {
    if (s[0] == s[1] && s[0] == s[2])
      res += po3(dp[s[0]]) + dp[s[0]] * (dp[s[0]] - 1) + dp[s[0]];
    if (s[0] == s[1] && s[1] != s[2]) {
      res += po2(dp[s[0]]) * dp[s[2]] + dp[s[0]] * dp[s[2]];
    }
    if (s[0] != s[1] && s[1] == s[2]) {
      res += po2(dp[s[1]]) * dp[s[0]] + dp[s[0]] * dp[s[2]];
    }
    if (s[0] != s[1] && s[1] != s[2]) res += dp[s[0]] * dp[s[1]] * dp[s[2]];
  }
  cout << res << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i < maxn; i++)
    for (int j = i; j < maxn; j += i) dziel[j].push_back(i);
  for (int i = 0; i <= 7; i++)
    for (int j = i; j <= 7; j++)
      for (int k = j; k <= 7; k++)
        if (dziala(i, j, k)) P.push_back({i, j, k});
  int t;
  cin >> t;
  while (t--) solve();
  return 0;
}
