#include <bits/stdc++.h>
using namespace std;
int a[100005], vis[100005];
int PrimeNum;
bool is_prime[200005];
int prime[200005];
void init() {
  PrimeNum = 0;
  is_prime[0] = is_prime[1] = false;
  for (int i = 2; i < 200005; i++) is_prime[i] = true;
  for (int i = 2; i < 200005; i++)
    if (is_prime[i]) {
      PrimeNum++;
      prime[PrimeNum] = i;
      for (int j = i * 2; j < 200005; j += i) is_prime[j] = false;
    }
}
int main() {
  ios::sync_with_stdio(false);
  init();
  int t;
  cin >> t;
  while (t--) {
    int a, b, c;
    cin >> a >> b >> c;
    map<int, int> m1, m2, m3;
    long long A = 1, B = 1, C = 1;
    int k = 1;
    while (a > 1) {
      while (a % prime[k] == 0) {
        a /= prime[k];
        m1[prime[k]]++;
      }
      k++;
      if (is_prime[a]) {
        m1[a]++;
        break;
      }
    }
    for (map<int, int>::iterator it = m1.begin(); it != m1.end(); it++) {
      A *= (it->second) + 1;
    }
    k = 1;
    while (b > 1) {
      while (b % prime[k] == 0) {
        b /= prime[k];
        m2[prime[k]]++;
      }
      k++;
      if (is_prime[b]) {
        m2[b]++;
        break;
      }
    }
    for (map<int, int>::iterator it = m2.begin(); it != m2.end(); it++) {
      B *= (it->second) + 1;
    }
    k = 1;
    while (c > 1) {
      while (c % prime[k] == 0) {
        c /= prime[k];
        m3[prime[k]]++;
      }
      k++;
      if (is_prime[c]) {
        m3[c]++;
        break;
      }
    }
    for (map<int, int>::iterator it = m3.begin(); it != m3.end(); it++) {
      C *= (it->second) + 1;
    }
    long long D = 1, E = 1, F = 1, G = 1;
    for (map<int, int>::iterator it1 = m1.begin(); it1 != m1.end(); it1++) {
      for (map<int, int>::iterator it2 = m2.begin(); it2 != m2.end(); it2++) {
        if (it1->first == it2->first) {
          D *= min(it1->second, it2->second) + 1;
        }
      }
    }
    for (map<int, int>::iterator it1 = m1.begin(); it1 != m1.end(); it1++) {
      for (map<int, int>::iterator it2 = m3.begin(); it2 != m3.end(); it2++) {
        if (it1->first == it2->first) {
          E *= min(it1->second, it2->second) + 1;
        }
      }
    }
    for (map<int, int>::iterator it1 = m3.begin(); it1 != m3.end(); it1++) {
      for (map<int, int>::iterator it2 = m2.begin(); it2 != m2.end(); it2++) {
        if (it1->first == it2->first) {
          F *= min(it1->second, it2->second) + 1;
        }
      }
    }
    for (map<int, int>::iterator it1 = m1.begin(); it1 != m1.end(); it1++) {
      for (map<int, int>::iterator it2 = m2.begin(); it2 != m2.end(); it2++) {
        for (map<int, int>::iterator it3 = m3.begin(); it3 != m3.end(); it3++) {
          if (it1->first == it2->first && it1->first == it3->first) {
            G *= min(min(it1->second, it2->second), it3->second) + 1;
          }
        }
      }
    }
    long long ans = 0;
    long long A_ = A - D - E + G;
    long long B_ = B - D - F + G;
    long long C_ = C - E - F + G;
    long long D_ = D - G;
    long long E_ = E - G;
    long long F_ = F - G;
    long long G_ = G;
    long long arr1[4] = {A_, D_, E_, G_};
    long long arr2[4] = {B_, D_, F_, G_};
    long long arr3[4] = {C_, E_, F_, G_};
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          if (i == 1 && j == 1) continue;
          if (i == 2 && k == 1) continue;
          if (i == 3 && j == 3) continue;
          if (i == 3 && k == 3) continue;
          if (k == 3 && j == 3) continue;
          if (j == 2 && k == 2) continue;
          ans += arr1[i] * arr2[j] * arr3[k];
        }
      }
    }
    ans -= A_ * F_ * G_;
    ans -= B_ * E_ * G_;
    ans -= C_ * D_ * G_;
    ans -= D_ * E_ * F_;
    ans -= 2 * E_ * F_ * G_;
    ans -= 2 * E_ * D_ * G_;
    ans -= 2 * D_ * F_ * G_;
    ans += (D_ * D_ - D_ * (D_ - 1) / 2) * C;
    ans += (E_ * E_ - E_ * (E_ - 1) / 2) * B;
    ans += (F_ * F_ - F_ * (F_ - 1) / 2) * A;
    ans += (G_ * G_ - G_ * (G_ - 1) / 2) * (A_ + B_ + C_ + D_ + E_ + F_);
    ans += G_ * (G_ - 1) * (G_ - 2) / 6 + G_ * (G_ - 1) + G_;
    cout << ans << endl;
  }
}
