#include <bits/stdc++.h>
using namespace std;
inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline long long C(int n, int m) {
  long long ret = 1ll;
  for (int i = n; i >= n - m + 1; i--) ret = ret * i;
  for (int i = 1; i <= m; i++) ret = ret / i;
  return ret;
}
const int maxn = 1e5 + 5;
const int N = 1e5;
bool p[maxn];
int prime[maxn], top = 0;
int div_num[maxn];
int e[maxn];
void init() {
  top = 0;
  div_num[1] = 1;
  for (int i = 2; i <= N; i++) {
    if (!p[i]) {
      prime[top++] = i;
      div_num[i] = 2;
      e[i] = 1;
    }
    for (int j = 0; j < top; j++) {
      if (i * prime[j] > N) break;
      p[i * prime[j]] = 1;
      if (i % prime[j] == 0) {
        div_num[i * prime[j]] = div_num[i] / (e[i] + 1) * (e[i] + 2);
        e[i * prime[j]] = e[i] + 1;
        break;
      }
      e[i * prime[j]] = 1;
      div_num[i * prime[j]] = div_num[i] * div_num[prime[j]];
    }
  }
}
bool check(int i, int j, int k) {
  int a[] = {i, j, k};
  vector<int> rk(3);
  iota(rk.begin(), rk.end(), 0);
  do {
    if ((a[rk[0]] & 1) && (a[rk[1]] & 2) && (a[rk[2]] & 4)) return true;
  } while (next_permutation(rk.begin(), rk.end()));
  return false;
}
int main() {
  init();
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  int T, a, b, c;
  cin >> T;
  for (; T--;) {
    cin >> a >> b >> c;
    int ab = gcd(a, b);
    int bc = gcd(b, c);
    int ac = gcd(a, c);
    int abc = gcd(ab, c);
    vector<int> cnt(8, 0);
    cnt[7] = div_num[abc];
    cnt[6] = div_num[ab] - div_num[abc];
    cnt[5] = div_num[ac] - div_num[abc];
    cnt[4] = div_num[a] - div_num[ab] - div_num[ac] + div_num[abc];
    cnt[3] = div_num[bc] - div_num[abc];
    cnt[2] = div_num[b] - div_num[ab] - div_num[bc] + div_num[abc];
    cnt[1] = div_num[c] - div_num[ac] - div_num[bc] + div_num[abc];
    long long res = 0;
    for (int i = 1; i < 8; i++)
      for (int j = i; j < 8; j++)
        for (int k = j; k < 8; k++) {
          if (!check(i, j, k)) continue;
          vector<int> now(8, 0);
          now[i]++;
          now[j]++;
          now[k]++;
          long long tmp = 1;
          for (int ii = 1; ii < 8; ii++)
            tmp *= C(cnt[ii] + now[ii] - 1, now[ii]);
          res += tmp;
        }
    cout << res << "\n";
  }
  return 0;
}
