#include <bits/stdc++.h>
using namespace std;
const int MAX_N = 100000 + 10;
int t;
int A, B, C;
int nd[MAX_N];
vector<int> perm[6];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void solve() {
  int c[8];
  c[7] = nd[gcd(C, gcd(B, A))];
  c[6] = nd[gcd(C, B)] - c[7];
  c[5] = nd[gcd(C, A)] - c[7];
  c[3] = nd[gcd(B, A)] - c[7];
  c[4] = nd[C] - c[7] - c[6] - c[5];
  c[2] = nd[B] - c[7] - c[6] - c[3];
  c[1] = nd[A] - c[7] - c[5] - c[3];
  int ans = 0;
  for (int i = 1; i <= 7; i++) {
    for (int j = i; j <= 7; j++) {
      for (int k = j; k <= 7; k++) {
        if ((i | j | k) != 7) continue;
        if ((i == j || j == k) && (j == 1 || j == 2 || j == 4)) continue;
        int t = c[j];
        if (i == j && j == k) {
          ans += (t * (t + 1) * (t + 2)) / 6;
        } else if (i == j) {
          ans += (t * (t + 1)) / 2 * c[k];
        } else if (j == k) {
          ans += (t * (t + 1)) / 2 * c[i];
        } else {
          ans += c[i] * c[j] * c[k];
        }
      }
    }
  }
  printf("%d\n", ans);
}
int main() {
  memset(nd, 0, sizeof(nd));
  for (int i = 1; i < MAX_N; i++) {
    for (int j = i; j < MAX_N; j += i) {
      nd[j]++;
    }
  }
  scanf("%d", &t);
  while (t--) {
    scanf("%d %d %d", &A, &B, &C);
    solve();
  }
  return 0;
}
