#include <bits/stdc++.h>
using ll = long long;
using namespace std;
template <typename T>
ostream& operator<<(ostream& out, vector<T> const& xs) {
  for (int i = 0; (i) < int(int(xs.size()) - 1); ++(i)) out << xs[i] << ' ';
  if (not xs.empty()) out << xs.back();
  return out;
}
ll powmod(ll x, ll y, ll m) {
  assert(0 <= x and x < m);
  assert(0 <= y);
  ll z = 1;
  for (ll i = 1; i <= y; i <<= 1) {
    if (y & i) z = z * x % m;
    x = x * x % m;
  }
  return z;
}
ll modinv(ll x, ll p) {
  assert(x % p != 0);
  return powmod(x, p - 2, p);
}
template <int32_t MOD>
int32_t fact(int n) {
  static vector<int32_t> memo(1, 1);
  while (n >= memo.size()) {
    memo.push_back(memo.back() * (int64_t)memo.size() % MOD);
  }
  return memo[n];
}
template <int32_t PRIME>
int32_t inv_fact(int n) {
  static vector<int32_t> memo(1, 1);
  while (n >= memo.size()) {
    memo.push_back(memo.back() * (int64_t)modinv(memo.size(), PRIME) % PRIME);
  }
  return memo[n];
}
template <int MOD>
int choose(int n, int r) {
  assert(0 <= r and r <= n);
  return fact<MOD>(n) * (ll)inv_fact<MOD>(n - r) % MOD * (ll)inv_fact<MOD>(r) %
         MOD;
}
template <int MOD>
int multichoose(int n, int r) {
  if (n == 0 and r == 0) return 1;
  return choose<MOD>(n + r - 1, r);
}
void split_to_disjoint(const vector<int>& a, const vector<int>& b,
                       const vector<int>& c, array<vector<int>, 8>& d) {
  int i = 0, j = 0, k = 0;
  while (a[i] != INT_MAX or b[j] != INT_MAX or c[k] != INT_MAX) {
    int x = min({a[i], b[j], c[k]});
    int mask = (x == a[i] ? 1 : 0) | (x == b[j] ? 2 : 0) | (x == c[k] ? 4 : 0);
    d[mask].push_back(x);
    if (x == a[i]) ++i;
    if (x == b[j]) ++j;
    if (x == c[k]) ++k;
  }
}
ll count_increasing(int i, int j, int k, const array<vector<int>, 8>& d) {
  constexpr int MOD = 1000000007;
  int a = d[i].size();
  int b = d[j].size();
  int c = d[k].size();
  if (not a or not b or not c) return 0;
  if (i == j and j == k) {
    return multichoose<MOD>(a, 3);
  } else if (i == j) {
    return multichoose<MOD>(a, 2) * c;
  } else if (j == k) {
    return multichoose<MOD>(b, 2) * a;
  } else if (k == i) {
    return multichoose<MOD>(c, 2) * b;
  } else {
    return a * b * c;
  }
}
int main() {
  constexpr int LIMIT = 100000;
  vector<vector<int> > factors(LIMIT + 1);
  for (int x = (1); (x) < int(LIMIT + 1); ++(x)) {
    for (int kx = x; kx <= LIMIT; kx += x) {
      factors[kx].push_back(x);
    }
  }
  for (int x = 0; (x) < int(LIMIT + 1); ++(x)) {
    factors[x].push_back(INT_MAX);
  }
  vector<array<int, 3> > ps;
  for (int i : {0x1, 0x3, 0x5, 0x7}) {
    for (int j : {0x2, 0x3, 0x6, 0x7}) {
      for (int k : {0x4, 0x5, 0x6, 0x7}) {
        array<int, 3> p = {{i, j, k}};
        sort(begin(p), end(p));
        ps.push_back(p);
      }
    }
  }
  sort(begin(ps), end(ps));
  ps.erase(unique(begin(ps), end(ps)), ps.end());
  int t;
  scanf("%d", &t);
  vector<int> a(t), b(t), c(t);
  for (int i = 0; (i) < int(t); ++(i)) {
    scanf("%d%d%d", &a[i], &b[i], &c[i]);
  }
  vector<ll> cnt(t);
  for (int i = 0; (i) < int(t); ++(i)) {
    array<vector<int>, 8> d;
    split_to_disjoint(factors[a[i]], factors[b[i]], factors[c[i]], d);
    for (auto p : ps) {
      cnt[i] += count_increasing(p[0], p[1], p[2], d);
    }
  }
  for (int i = 0; (i) < int(t); ++(i)) {
    printf("%lld\n", cnt[i]);
  }
  return 0;
}
