#include <bits/stdc++.h>
using namespace std;
const int MAX = 1e5 + 20;
int t;
const int MAXD = 89;
vector<pair<long long, long long> > factors;
int factorTmp[MAX];
void factor(long long C) {
  factors.resize(0);
  long long bound = sqrt(C + 0.5);
  for (int i = 2; i <= bound; i++) factorTmp[i] = 0;
  for (int i = 2; i <= bound;) {
    if (C % i == 0) {
      ++factorTmp[i];
      C /= i;
    } else
      i++;
  }
  for (int i = 2; i <= bound; i++)
    if (factorTmp[i]) factors.push_back({i, factorTmp[i]});
  if (C != 1) factors.push_back({C, 1});
}
int an[3];
void sol(int pos, int val, unordered_set<int> &allot) {
  if (pos == factors.size()) {
    allot.insert(val);
  } else {
    int e = factors[pos].second, d = factors[pos].first;
    int base = 1;
    for (int sel = 0; sel <= e; sel++) {
      sol(pos + 1, val * base, allot);
      base *= d;
    }
  }
}
int c2(int a) { return a * (a - 1) / 2; }
int c3(int a) { return a * (a - 1) * (a - 2) / 6; }
int gcd(int a, int b) {
  if (b == 0)
    return a;
  else
    return gcd(b, a % b);
}
int cnt[10];
unordered_set<int> hh[MAX];
int main() {
  scanf("%d", &t);
  for (int val = 1; val <= 100000; val++) {
    factor(val);
    sol(0, 1, hh[val]);
  }
  while (t--) {
    scanf("%d%d%d", &an[0], &an[1], &an[2]);
    int z0 = hh[an[0]].size();
    int z1 = hh[an[1]].size();
    int z2 = hh[an[2]].size();
    int z01 = hh[gcd(an[0], an[1])].size();
    int z02 = hh[gcd(an[0], an[2])].size();
    int z12 = hh[gcd(an[1], an[2])].size();
    int z012 = hh[gcd(gcd(an[0], an[1]), an[2])].size();
    cnt[7] = z012, cnt[6] = z12 - z012, cnt[5] = z02 - z012,
    cnt[3] = z01 - z012, cnt[1] = z0 - z01 - z02 + z012,
    cnt[2] = z1 - z01 - z12 + z012, cnt[4] = z2 - z02 - z12 + z012;
    int t1 = 0, t2 = 0, t3 = 0;
    int tmp4 = 0;
    for (int i = 1; i <= 7; i++) tmp4 += cnt[i];
    t1 += cnt[1] * cnt[2] * cnt[4];
    t1 += c3(cnt[7]);
    t1 += c2(cnt[6]) * (cnt[1] + cnt[5] + cnt[3] + cnt[7]) +
          c2(cnt[5]) * (cnt[6] + cnt[3] + cnt[2] + cnt[7]) +
          c2(cnt[3]) * (cnt[6] + cnt[5] + cnt[4] + cnt[7]) +
          c2(cnt[7]) * (tmp4 - cnt[7]);
    int tmp1 = cnt[3] + cnt[5] + cnt[6] + cnt[7];
    int tmp2 = cnt[3] * (cnt[5] + cnt[6] + cnt[7]) +
               cnt[5] * (cnt[6] + cnt[7]) + cnt[6] * cnt[7];
    int tmp3 = cnt[3] * cnt[5] * cnt[6] + cnt[3] * cnt[5] * cnt[7] +
               cnt[3] * cnt[6] * cnt[7] + cnt[5] * cnt[6] * cnt[7];
    t1 += cnt[4] * cnt[2] * (tmp1 - cnt[6]) +
          cnt[4] * cnt[1] * (tmp1 - cnt[5]) +
          cnt[2] * cnt[1] * (tmp1 - cnt[3]) +
          (cnt[4] + cnt[2] + cnt[1]) * tmp2 + tmp3;
    t3 += cnt[7];
    t2 += cnt[6] * (cnt[1] + cnt[5] + cnt[3] + cnt[7]) +
          cnt[5] * (cnt[6] + cnt[3] + cnt[2] + cnt[7]) +
          cnt[3] * (cnt[6] + cnt[5] + cnt[4] + cnt[7]) + cnt[7] * (tmp4 - 1);
    printf("%d\n", t1 + t2 + t3);
  }
  return 0;
}
