#include <bits/stdc++.h>
using namespace std;
unordered_map<int, int> pp;
vector<int> g[100005];
const int N = 101010;
int lei[8];
int s[N / 2];
bool p[N];
int ans[100100];
int k = 0, l = 1;
int ji[8][8][8];
void shusu() {
  memset(p, false, sizeof(p));
  for (int i = 2; i < N; i++) {
    if (!p[i]) {
      s[k++] = i;
      for (int j = 2; i * j < N; j++) {
        p[i * j] = 1;
      }
    }
  }
}
int asd(int x) {
  if (pp[x]) return pp[x];
  int z = x;
  int ant, sum = 1;
  g[z].push_back(1);
  for (int i = 0; i < k && s[i] <= x; i++) {
    ant = 0;
    if (x % s[i] == 0) {
      int a = s[i];
      int m = g[z].size();
      while (x % s[i] == 0) {
        for (int i = 0; i < m; i++) {
          g[z].push_back(a * g[z][i]);
        }
        a = a * s[i];
        x /= s[i];
        ant++;
      }
    }
    sum *= (ant + 1);
  }
  return pp[z] = sum;
}
int main() {
  int n;
  int a, b, c;
  cin >> n;
  shusu();
  while (n--) {
    scanf("%d%d%d", &a, &b, &c);
    int a1 = asd(a);
    int b1 = asd(b);
    int c1 = asd(c);
    memset(ans, 0, sizeof(ans));
    memset(lei, 0, sizeof(lei));
    memset(ji, 0, sizeof(ji));
    for (int i = 0; i < a1; i++) {
      ans[g[a][i]]++;
      lei[1]++;
    }
    int time2 = 0;
    for (int j = 0; j < b1; j++) {
      if (ans[g[b][j]] == 1) {
        ans[g[b][j]] = 2;
        lei[2]++;
        lei[1]--;
      } else {
        ans[g[b][j]] = 5;
        lei[5]++;
      }
    }
    for (int z = 0; z < c1; z++) {
      int t = g[c][z];
      if (ans[t] == 0) {
        lei[7]++;
      } else if (ans[t] == 1) {
        lei[3]++;
        lei[1]--;
      } else if (ans[t] == 5) {
        lei[5]--;
        lei[6]++;
      } else {
        lei[4]++;
        lei[2]--;
      }
    }
    int sum = 0;
    for (int i = 1; i <= 4; i++) {
      for (int j = 2; j <= 6; j++) {
        if (j != 3) {
          for (int k = 3; k <= 7; k++) {
            if (k != 5 && ji[i][j][k] == 0) {
              if (i != j && i != k && j != k) {
                sum = sum + lei[i] * lei[j] * lei[k];
              } else if (i == j && j == k) {
                sum = sum + lei[i] * lei[i] +
                      (lei[i]) * (lei[i] - 1) * (lei[i] - 2) / 6;
              } else if (i == j) {
                sum += (lei[i] * (lei[i] - 1) / 2 + lei[i]) * lei[k];
              } else if (j == k) {
                sum += (lei[j] * (lei[j] - 1) / 2 + lei[j]) * lei[i];
              } else {
                sum += (lei[i] * (lei[i] - 1) / 2 + lei[i]) * lei[j];
              }
              ji[i][j][k] = 1;
              ji[j][i][k] = 1;
              ji[k][j][i] = 1;
              ji[k][i][j] = 1;
              ji[i][k][j] = 1;
              ji[j][k][i] = 1;
            }
          }
        }
      }
    }
    printf("%d\n", sum);
  }
}
