#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
int main() {
  auto get_factors = [](int n) {
    vector<int> ret;
    for (int i = 1; i * i <= n; i++) {
      if (n % i == 0) {
        ret.push_back(i);
        if (i * i != n) ret.push_back(n / i);
      }
    }
    sort(ret.begin(), ret.end());
    return ret;
  };
  vector<vector<int>> factors(1e5 + 1);
  for (int i = (1); i <= (1e5); ++i) factors[i] = get_factors(i);
  ios::sync_with_stdio(false);
  int tc;
  cin >> tc;
  while (tc--) {
    int x[3], cnt[8] = {0};
    cin >> x[0] >> x[1] >> x[2];
    vector<int> v;
    for (int i = 0; i < 3; i++) {
      for (auto val : factors[x[i]]) v.push_back(val);
    }
    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());
    for (auto val : v) {
      int mask = 0;
      for (int i = 0; i < 3; i++) {
        if (x[i] % val == 0) mask |= 1 << i;
      }
      cnt[mask]++;
    }
    int ans = 0;
    for (int a = 1; a < 8; a++) {
      for (int b = a; b < 8; b++) {
        int t1 = a | b;
        if (t1 == (t1 & -t1)) continue;
        for (int c = b; c < 8; c++) {
          int t2 = a | c, t3 = b | c;
          if (t2 == (t2 & -t2)) continue;
          if (t3 == (t3 & -t3)) continue;
          if ((a | b | c) != 7) continue;
          if (a != b && a != c && b != c) {
            ans += cnt[a] * cnt[b] * cnt[c];
          } else if (a == b && b == c) {
            int n = cnt[a] + 2;
            ans += n * (n - 1) * (n - 2) / 6;
          } else if (a == b) {
            ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[c];
          } else if (a == c) {
            ans += cnt[a] * (cnt[a] + 1) / 2 * cnt[b];
          } else if (b == c) {
            ans += cnt[b] * (cnt[b] + 1) / 2 * cnt[a];
          }
        }
      }
    }
    cout << ans << endl;
  }
}
