#include <bits/stdc++.h>
using namespace std;
const long long MAXN = 1e5 + 5;
const long long INF = 1e9;
const long long MOD = 1e9 + 7;
vector<int> divs[MAXN];
long long ans;
int gcd(int x, int y) {
  if (y > x) swap(x, y);
  if (y == 0) return x;
  return gcd(x % y, y);
}
long long newton(long long n, long long k) {
  if (k == 3)
    return (n + 2) * (n + 1) * n / 6;
  else
    return (n + 1) * n / 2;
}
vector<int> common(vector<int> x, vector<int> y) {
  int fx = 0, fy = 0;
  vector<int> res;
  while (fx < (int)x.size() || fy < (int)y.size()) {
    if (fx == (int)x.size()) {
      res.push_back(y[fy]);
      fy++;
    } else if (fy == (int)y.size()) {
      res.push_back(x[fx]);
      fx++;
    } else {
      if (x[fx] < y[fy]) {
        res.push_back(x[fx]);
        fx++;
      } else if (x[fx] > y[fy]) {
        res.push_back(y[fy]);
        fy++;
      } else {
        res.push_back(x[fx]);
        fx++;
        fy++;
      }
    }
  }
  return res;
}
int without(vector<int> &v, int yy = 0, int zz = 0) {
  int ile = 0;
  for (int u : v)
    if ((!yy || (yy && yy % u != 0)) && (!zz || (zz && zz % u != 0))) ile++;
  return ile;
}
void solve(int A, int B, int C) {
  vector<int> abc = common(common(divs[A], divs[B]), divs[C]);
  ans = 0;
  ans += newton(without(abc), 3);
  ans -= newton(without(abc, A), 3) + newton(without(abc, B), 3) +
         newton(without(abc, C), 3);
  ans -= newton(without(abc, A, B), 2) * divs[gcd(A, B)].size() +
         newton(without(abc, A, C), 2) * divs[gcd(A, C)].size() +
         newton(without(abc, B, C), 2) * divs[gcd(B, C)].size();
  ans += newton(without(abc, A, B), 3) + newton(without(abc, A, C), 3) +
         newton(without(abc, B, C), 3);
  cout << ans << "\n";
}
int main() {
  ios_base::sync_with_stdio(0);
  cin.tie(NULL);
  cout.tie(NULL);
  for (int i = 1; i < MAXN; i++)
    for (int j = i; j < MAXN; j += i) divs[j].push_back(i);
  int T, a, b, c;
  cin >> T;
  while (T--) {
    cin >> a >> b >> c;
    solve(a, b, c);
  }
  return 0;
}
