#include <bits/stdc++.h>
using namespace std;
vector<long long> erat;
long long gcd(long long a, long long b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long nd(long long a) {
  map<long long, long long> m;
  while (a != 1) {
    ++m[erat[a]];
    a /= erat[a];
  }
  long long count = 1;
  for (auto e : m) count *= e.second + 1;
  return count;
}
int main() {
  vector<vector<vector<bool> > > count(
      8, vector<vector<bool> >(8, vector<bool>(8, true)));
  count[1][7][6] = false;
  count[3][7][6] = false;
  count[5][3][6] = false;
  count[5][3][7] = false;
  count[5][7][6] = false;
  count[7][2][5] = false;
  count[7][3][4] = false;
  count[7][3][5] = false;
  count[7][3][6] = false;
  count[7][3][7] = false;
  count[7][6][5] = false;
  count[7][7][5] = false;
  count[7][7][6] = false;
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  erat = vector<long long>(1e5 + 1, 1);
  erat[0] = erat[1] = 1;
  for (long long i = 2; i <= 1e5; ++i) {
    if (erat[i] == 1) {
      erat[i] = i;
      for (long long j = i * i; j <= 1e5; j += i) {
        if (erat[j] == 1) erat[j] = i;
      }
    }
  }
  long long t;
  cin >> t;
  while (t--) {
    long long a, b, c;
    cin >> a >> b >> c;
    long long d = gcd(a, b);
    long long e = gcd(a, c);
    long long f = gcd(b, c);
    long long g = gcd(d, c);
    a = nd(a);
    b = nd(b);
    c = nd(c);
    d = nd(d);
    e = nd(e);
    f = nd(f);
    g = nd(g);
    d -= g, e -= g, f -= g;
    a -= d + e + g, b -= d + f + g, c -= e + f + g;
    vector<long long> v(8);
    v[1] = a, v[2] = b, v[3] = d, v[4] = c, v[5] = e, v[6] = f, v[7] = g;
    long long total = 0;
    for (int i = 0; i < 4; ++i) {
      for (int j = 0; j < 4; ++j) {
        for (int k = 0; k < 4; ++k) {
          int l = 2 * i + 1;
          int m = 2 + j;
          if (j >= 2) m += 2;
          int p = 4 + k;
          if (count[l][m][p]) {
            if (l == m) {
              if (m == p)
                total += v[l] * (v[m] + 1) * (v[p] + 2) / 6;
              else
                total += v[l] * (v[m] + 1) * v[p] / 2;
            } else if (l == p or m == p)
              total += v[l] * v[m] * (v[p] + 1) / 2;
            else
              total += v[l] * v[m] * v[p];
          }
        }
      }
    }
    cout << total << endl;
  }
}
