#include <bits/stdc++.h>
using namespace std;
vector<int> d[100001];
int dp[2][8][8];
int who[400];
int good[8][8][8];
int seen[100001], sid;
int main() {
  clock_t T = clock();
  for (int i = 1; i <= 100000; ++i)
    for (int j = i; j <= 100000; j += i) d[j].push_back(i);
  for (int a = 0; a < 8; ++a)
    for (int b = 0; b < 8; ++b)
      for (int c = 0; c < 8; ++c) {
        for (int i = 0; i < 3; ++i)
          for (int j = 0; j < 3; ++j)
            for (int k = 0; k < 3; ++k)
              if (i != j && i != k && j != k)
                if ((a >> i) & 1)
                  if ((b >> j) & 1)
                    if ((c >> k) & 1) good[a][b][c] = 1;
      }
  int t;
  scanf("%d", &t);
  map<vector<int>, int> vis;
  vector<int> cur;
  vector<int> v(3);
  while (t--) {
    cur.clear();
    ++sid;
    for (int x, i = 0; i < 3; ++i) {
      scanf("%d", &x);
      v[i] = x;
      for (auto &a : d[x])
        if (seen[a] != sid) {
          seen[a] = sid;
          cur.push_back(a);
        }
    }
    sort(v.begin(), v.end());
    int has[8] = {};
    for (int i = 0; i < cur.size(); ++i) {
      who[i] = 0;
      for (int j = 0; j < 3; ++j)
        if (v[j] % cur[i] == 0) who[i] |= 1 << j;
      ++has[who[i]];
    }
    int n = 8;
    for (int i = n - 1; i >= 0; --i)
      for (int b = 7; b >= 0; --b)
        for (int a = 7; a >= 0; --a) {
          int j = 0;
          if (a) ++j;
          if (b) ++j;
          int &cur = dp[i & 1][a][b];
          cur = 0;
          if (j == 2) {
            if (i != n - 1) cur += dp[1 & ~i][a][b];
            cur += has[i] * good[a][b][i];
          } else {
            if (i != n - 1) {
              cur += dp[1 & ~i][a][b];
              cur += has[i] * dp[1 & ~i][(j == 0 ? i : a)][(j == 1 ? i : b)];
            }
            if (j == 0) {
              if (i != n - 1) {
                cur += has[i] * (has[i] - 1) / 2 * dp[1 & ~i][i][i];
                cur += has[i] * dp[1 & ~i][i][i];
              }
              cur += has[i] * (has[i] - 1) * (has[i] - 2) / 6 * good[i][i][i];
              cur += has[i] * (has[i] - 1) / 2 * 2 * good[i][i][i];
              cur += has[i] * good[i][i][i];
            }
            if (j == 1) {
              cur += has[i] * (has[i] - 1) / 2 * good[a][i][i];
              cur += has[i] * good[a][i][i];
            }
          }
        }
    printf("%d\n", dp[0][0][0]);
  }
  return 0;
}
