#include <bits/stdc++.h>
using namespace std;
using int64 = long long int;
int gcd(int a, int b) {
  while (b > 0) {
    const int tmp = a % b;
    a = b;
    b = tmp;
  }
  return a;
}
int solveSingleTest(const int a, const int b, const int c,
                    const vector<int>& divisors,
                    const vector<vector<vector<bool>>>& good_masks) {
  const int gab = gcd(a, b);
  const int gac = gcd(a, c);
  const int gbc = gcd(b, c);
  const int gabc = gcd(gab, c);
  vector<int> count(8);
  count[1] = divisors[a] - divisors[gab] - divisors[gac] + divisors[gabc];
  count[2] = divisors[b] - divisors[gab] - divisors[gbc] + divisors[gabc];
  count[3] = divisors[gab] - divisors[gabc];
  count[4] = divisors[c] - divisors[gac] - divisors[gbc] + divisors[gabc];
  count[5] = divisors[gac] - divisors[gabc];
  count[6] = divisors[gbc] - divisors[gabc];
  count[7] = divisors[gabc];
  int answer = 0;
  for (int m1 = 1; m1 < 8; ++m1) {
    if (good_masks[m1][m1][m1]) {
      answer += count[m1] * (count[m1] + 1) * (count[m1] + 2) / 6;
    }
    for (int m2 = m1 + 1; m2 < 8; ++m2) {
      if (good_masks[m1][m2][m2]) {
        answer += count[m1] * count[m2] * (count[m2] + 1) / 2;
      }
      if (good_masks[m1][m1][m2]) {
        answer += count[m1] * count[m2] * (count[m1] + 1) / 2;
      }
      for (int m3 = m2 + 1; m3 < 8; ++m3) {
        if (good_masks[m1][m2][m3]) {
          answer += count[m1] * count[m2] * count[m3];
        }
      }
    }
  }
  return answer;
}
void solve() {
  const int maxn = 100000;
  vector<int> divisors(maxn + 1, 1);
  for (size_t i = 2; i < divisors.size(); ++i) {
    for (size_t j = i; j < divisors.size(); j += i) {
      ++divisors[j];
    }
  }
  vector<vector<vector<bool>>> good_masks(
      8, vector<vector<bool>>(8, vector<bool>(8)));
  for (int m1 = 0; m1 < 8; ++m1) {
    for (int m2 = 0; m2 < 8; ++m2) {
      for (int m3 = 0; m3 < 8; ++m3) {
        if (((m1 & 1) != 0) && ((m2 & 2) != 0) && ((m3 & 4) != 0)) {
          good_masks[m1][m2][m3] = true;
        }
        if (((m1 & 1) != 0) && ((m3 & 2) != 0) && ((m2 & 4) != 0)) {
          good_masks[m1][m2][m3] = true;
        }
        if (((m2 & 1) != 0) && ((m1 & 2) != 0) && ((m3 & 4) != 0)) {
          good_masks[m1][m2][m3] = true;
        }
        if (((m2 & 1) != 0) && ((m3 & 2) != 0) && ((m1 & 4) != 0)) {
          good_masks[m1][m2][m3] = true;
        }
        if (((m3 & 1) != 0) && ((m1 & 2) != 0) && ((m2 & 4) != 0)) {
          good_masks[m1][m2][m3] = true;
        }
        if (((m3 & 1) != 0) && ((m2 & 2) != 0) && ((m1 & 4) != 0)) {
          good_masks[m1][m2][m3] = true;
        }
      }
    }
  }
  int t;
  scanf("%d", &t);
  for (int i = 0; i < t; ++i) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    cout << solveSingleTest(a, b, c, divisors, good_masks) << "\n";
  }
}
int main() {
  solve();
  return 0;
}
