#include <bits/stdc++.h>
using namespace std;
const int MOD = 1e9 + 7;
const int C = 26;
void add(int &x, int y) {
  x += y;
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
}
int fix(int x) {
  while (x >= MOD) x -= MOD;
  while (x < 0) x += MOD;
  return x;
}
int pw(int a, int b) {
  int ret = 1;
  while (b) {
    if (b & 1) ret = 1ll * ret * a % MOD;
    b >>= 1;
    a = 1ll * a * a % MOD;
  }
  return ret;
}
bitset<3> bs(int x) { return bitset<3>(x); }
const int MAXN = 1e5 + 10;
vector<int> vec[MAXN];
int mark[MAXN], tt;
int single(int x) { return (x & (x - 1)) == 0; }
void solve() {
  ++tt;
  int a[3];
  vector<int> sec;
  for (int i = 0; i < 3; i++) {
    cin >> a[i];
    for (int x : vec[a[i]]) {
      if (mark[x] ^ tt) sec.push_back(x);
      mark[x] = tt;
    }
  }
  int cnt[8] = {};
  for (int x : sec) {
    int mask = 0;
    for (int i = 0; i < 3; i++)
      if (a[i] % x == 0) mask ^= 1 << i;
    ++cnt[mask];
  }
  int ans = 0;
  for (int i = 0; i < (1 << 3); i++) {
    for (int j = i; j < (1 << 3); j++) {
      for (int k = j; k < (1 << 3); k++) {
        if ((i | j | k) != (1 << 3) - 1) continue;
        if ((i == j && single(i)) || (j == k && single(j))) continue;
        int cnt_single = single(i) + single(j) + single(k);
        int memo_ans = ans;
        if (cnt_single == 3) {
          ans += cnt[i] * cnt[j] * cnt[k];
        } else if (cnt_single == 2) {
          ans += cnt[i] * cnt[j] * cnt[k];
        } else if (cnt_single == 1) {
          if (single(i)) {
            if (j == k) {
              ans += cnt[i] * (cnt[j] + 1) * cnt[j] / 2;
            } else {
              ans += cnt[i] * cnt[j] * cnt[k];
            }
          }
          if (single(j)) {
            if (i == k) {
              ans += cnt[j] * (cnt[i] + 1) * cnt[i] / 2;
            } else {
              ans += cnt[i] * cnt[j] * cnt[k];
            }
          }
          if (single(k)) {
            if (i == j) {
              ans += cnt[k] * (cnt[i] + 1) * cnt[i] / 2;
            } else {
              ans += cnt[i] * cnt[j] * cnt[k];
            }
          }
        } else if (i == j && j == k) {
          ans += (cnt[i] + 2) * (cnt[i] + 1) * cnt[i] / 6;
        } else if (i == j) {
          ans += cnt[k] * (cnt[i] + 1) * cnt[i] / 2;
        } else if (j == k) {
          ans += cnt[i] * (cnt[j] + 1) * cnt[j] / 2;
        } else {
          ans += cnt[i] * cnt[j] * cnt[k];
        }
        if (ans != memo_ans && 0) {
          cerr << bs(i) << " " << bs(j) << " " << bs(k) << "\n";
          cerr << "ans: " << memo_ans << "\n";
          cerr << "now ans: " << ans << "\n\n";
        }
      }
    }
  }
  cout << ans << "\n";
}
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  for (int i = 1; i < MAXN; i++)
    for (int j = i; j < MAXN; j += i) vec[j].push_back(i);
  int te = 1;
  cin >> te;
  for (int w = 1; w <= te; w++) {
    solve();
  }
  return 0;
}
