#include <bits/stdc++.h>
using namespace std;
int A, B, C;
int a[5];
int vis[100006][3];
int vis2[100006];
int c[8];
vector<int> prime[100006];
int kase = 0;
int sum2[200], sum3[200];
int dd[3][4] = {
    {1, 3, 5, 7},
    {2, 3, 6, 7},
    {4, 5, 6, 7},
};
struct node {
  int A, B, C;
  bool operator<(const node &rhs) const {
    return A < rhs.A || A == rhs.A && B < rhs.B ||
           A == rhs.A && B == rhs.B && C < rhs.C;
  }
  node(int a = 0, int b = 0, int c = 0) {
    if (b < a) swap(a, b);
    if (c < a) swap(a, c);
    if (c < b) swap(b, c);
    A = a, B = b, C = c;
  }
};
set<node> S;
void init() {
  for (int i = 1; i <= 100000; i++) {
    for (int j = i; j <= 100000; j += i) {
      prime[j].push_back(i);
    }
  }
  for (int i = 1; i <= 128; i++) {
    sum2[i] = (1 + i) * i / 2;
    for (int j = 1; j <= i; j++) {
      sum3[i] += (1 + j) * j / 2;
    }
  }
}
int main() {
  int T;
  scanf("%d", &T);
  init();
  while (T--) {
    ++kase;
    for (int i = 0; i < 3; i++) scanf("%d", &a[i]);
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < prime[a[i]].size(); j++) {
        vis[prime[a[i]][j]][i] = kase;
      }
    }
    memset(c, 0, sizeof(c));
    for (int i = 0; i < 3; i++) {
      for (int j = 0; j < prime[a[i]].size(); j++) {
        int o = prime[a[i]][j];
        if (vis2[o] != kase) {
          vis2[o] = kase;
          int t = 0;
          for (int k = 0; k < 3; k++) {
            if (vis[o][k] == kase) t += (1 << k);
          }
          c[t]++;
        }
      }
    }
    S.clear();
    long long ans = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          if (S.count(node(dd[0][i], dd[1][j], dd[2][k])))
            continue;
          else
            S.insert(node(dd[0][i], dd[1][j], dd[2][k]));
          if (dd[0][i] != dd[1][j] && dd[1][j] != dd[2][k] &&
              dd[2][k] != dd[0][i]) {
            ans += c[dd[0][i]] * c[dd[1][j]] * c[dd[2][k]];
          } else if (dd[0][i] == dd[1][j] && dd[1][j] != dd[2][k]) {
            ans += sum2[c[dd[0][i]]] * c[dd[2][k]];
          } else if (dd[0][i] == dd[2][k] && dd[1][j] != dd[0][i]) {
            ans += (sum2[c[dd[0][i]]]) * c[dd[1][j]];
          } else if (dd[1][j] == dd[2][k] && dd[0][i] != dd[1][j]) {
            ans += (sum2[c[dd[1][j]]]) * c[dd[0][i]];
          } else {
            ans += sum3[c[7]];
          }
        }
      }
    }
    printf("%lld\n", ans);
  }
}
