#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 233;
vector<int> s[maxn];
int a[maxn], v[100], y[3], z[3];
int vis[maxn];
void work(int x) {
  stack<int> S;
  for (int i = 1; i <= sqrt(x); i++)
    if (x % i == 0) {
      s[x].push_back(i);
      if (x / i != i) S.push(x / i);
    }
  while (!S.empty()) {
    s[x].push_back(S.top());
    S.pop();
  }
  return;
}
int main() {
  for (int i = 1; i <= 100000; i++) work(i);
  int T;
  cin >> T;
  while (T--) {
    cin >> a[0] >> a[1] >> a[2];
    memset(v, 0, sizeof(v));
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < s[a[i]].size(); j++) {
        vis[s[a[i]][j]] |= (1 << i);
      }
    for (int i = 0; i < 3; i++)
      for (int j = 0; j < s[a[i]].size(); j++)
        if (vis[s[a[i]][j]]) {
          int t = vis[s[a[i]][j]];
          vis[s[a[i]][j]] = 0;
          v[t]++;
        }
    int ans = 0;
    for (int i = 1; i < 8; i++)
      for (int j = 1; j < i; j++)
        for (int k = 1; k < j; k++)
          if ((i | j | k) == 7) {
            ans += v[i] * v[j] * v[k];
          }
    int x = v[7];
    ans += x + x * (x - 1);
    if (x >= 3) ans += x * (x - 1) * (x - 2) / 6;
    ans += (x + x * (x - 1) / 2) * (v[1] + v[2] + v[3] + v[4] + v[5] + v[6]);
    y[0] = v[6];
    y[1] = v[5];
    y[2] = v[3];
    z[0] = v[4];
    z[1] = v[2];
    z[2] = v[1];
    int sum = y[0] + y[1] + y[2];
    for (int i = 0; i < 3; i++)
      ans += (y[i] + y[i] * (y[i] - 1) / 2) * (x + z[2 - i] + sum - y[i]);
    printf("%d\n", ans);
  }
  return 0;
}
