#include <bits/stdc++.h>
using namespace std;
void _add(int &a, int b) { a = (a + b) % 1000000007; }
void _sub(int &a, int b) { a = (a + 1000000007 - b) % 1000000007; }
void _mul(int &a, int b) { a = (long long)a * b % 1000000007; }
void _max(int &a, int b) { a = max(a, b); }
void _min(int &a, int b) { a = min(a, b); }
long long gcd(long long a, long long b) {
  if (!b) return a;
  return gcd(b, a % b);
}
long long pw(long long a, long long b) {
  long long res(1);
  while (b) {
    if (b & 1) res = res * a % 1000000007;
    a = a * a % 1000000007;
    b >>= 1;
  }
  return res;
}
long long pwM(long long a, long long b, long long mod) {
  long long res(1);
  while (b) {
    if (b & 1) res = res * a % mod;
    a = a * a % mod;
    b >>= 1;
  }
  return res;
}
const int infi = 2147483647;
const long long infl = 9223372036854775807ll;
const double PI = 3.14159265358979323846;
int n, m, k, q;
vector<int> d[100010];
vector<int> ds[10], aa, bb, cc;
multiset<pair<pair<int, int>, int> > s;
set<pair<pair<int, int>, int> > vis, ss;
int D[4];
long long cnt[10];
void print(int x) {
  if (x == 1) cout << "A";
  if (x == 2) cout << "B";
  if (x == 3) cout << "C";
  if (x == 4) cout << "AB";
  if (x == 5) cout << "AC";
  if (x == 6) cout << "BC";
  if (x == 7) cout << "ABC";
  putchar(' ');
}
long long calc_3(long long x) {
  long long res(0);
  if (x >= 1) res += x;
  if (x >= 2) res += x * (x - 1);
  if (x >= 3) res += x * (x - 1) * (x - 2) / 6;
  return res;
}
long long calc_2(long long x) {
  long long res(0);
  if (x >= 1) res += x;
  if (x >= 2) res += x * (x - 1) / 2;
  return res;
}
int main() {
  aa.push_back(1);
  aa.push_back(4);
  aa.push_back(5);
  aa.push_back(7);
  bb.push_back(2);
  bb.push_back(4);
  bb.push_back(6);
  bb.push_back(7);
  cc.push_back(3);
  cc.push_back(6);
  cc.push_back(5);
  cc.push_back(7);
  for (auto x : aa)
    for (auto y : bb)
      for (auto z : cc) {
        D[0] = x, D[1] = y, D[2] = z;
        sort(D, D + 3);
        s.insert(make_pair(make_pair(D[0], D[1]), D[2]));
      }
  for (int i = 1, lim = 1e5; i <= lim; ++i) {
    for (int j = 1, lim = sqrt(i); j <= lim; ++j) {
      if (i % j == 0) {
        d[i].push_back(j);
        if (j != i / j) d[i].push_back(i / j);
      }
    }
  }
  int T, A1, B1, C1;
  scanf("%d", &T);
  while (T--) {
    vis.clear();
    memset(cnt, 0, sizeof cnt);
    scanf("%d", &A1), scanf("%d", &B1), scanf("%d", &C1);
    for (int i = 1, lim = 7; i <= lim; ++i) ds[i].clear();
    for (auto x : d[A1]) {
      if (B1 % x == 0 && C1 % x == 0)
        ds[7].push_back(x);
      else if (B1 % x == 0) {
        ds[4].push_back(x);
      } else if (C1 % x == 0)
        ds[5].push_back(x);
      else
        ds[1].push_back(x);
    }
    for (auto x : d[B1]) {
      if (A1 % x == 0 && C1 % x == 0)
        continue;
      else if (C1 % x == 0) {
        ds[6].push_back(x);
      } else if (A1 % x != 0)
        ds[2].push_back(x);
    }
    for (auto x : d[C1]) {
      if (A1 % x != 0 && B1 % x != 0) ds[3].push_back(x);
    }
    for (int i = 1, lim = 7; i <= lim; ++i) cnt[i] = ds[i].size();
    long long ans = d[A1].size();
    ans *= d[B1].size();
    ans *= d[C1].size();
    for (auto x : aa)
      for (auto y : bb)
        for (auto z : cc) {
          D[0] = x, D[1] = y, D[2] = z;
          sort(D, D + 3);
          auto p = make_pair(make_pair(D[0], D[1]), D[2]);
          if (vis.count(p)) continue;
          vis.insert(p);
          m = s.count(p);
          long long tmp = cnt[D[0]] * cnt[D[1]] * cnt[D[2]] * m, tmp1 = tmp / m;
          ans -= tmp;
          if (D[1] == D[0] && D[2] == D[0]) {
            tmp1 = calc_3(cnt[D[0]]);
          } else if (D[1] == D[0]) {
            tmp1 = cnt[D[2]] * calc_2(cnt[D[0]]);
          } else if (D[2] == D[1]) {
            tmp1 = cnt[D[0]] * calc_2(cnt[D[1]]);
          }
          ans += tmp1;
        }
    printf("%I64d", (ans));
    putchar('\n');
  }
  return 0;
}
