#include <bits/stdc++.h>
const int N = 100005;
long long num1[N], num2[N], num3[N];
void init() {
  memset(num1, 0, sizeof(num1));
  memset(num2, 0, sizeof(num2));
  memset(num3, 0, sizeof(num3));
  for (int i = 1; i < N; ++i) {
    for (int j = i; j < N; j += i) {
      num1[j] += 1;
    }
  }
  num2[0] = 0;
  for (int i = 1; i < N; ++i) {
    num2[i] = num2[i - 1] + i;
  }
  num3[0] = 0;
  for (int i = 1; i < N; ++i) {
    num3[i] = num3[i - 1] + num2[i];
  }
}
int gcd(int x, int y) { return y == 0 ? x : gcd(y, x % y); }
int main() {
  init();
  int t;
  scanf("%d", &t);
  while (t--) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    int gcd_3 = gcd(x, gcd(y, z));
    int gcd_xy = gcd(x, y);
    int gcd_yz = gcd(y, z);
    int gcd_xz = gcd(x, z);
    long long g_3 = num1[gcd_3];
    long long g_xy = num1[gcd_xy] - num1[gcd_3];
    long long g_xz = num1[gcd_xz] - num1[gcd_3];
    long long g_yz = num1[gcd_yz] - num1[gcd_3];
    long long g_x = num1[x] + num1[gcd_3] - num1[gcd_xy] - num1[gcd_xz];
    long long g_y = num1[y] + num1[gcd_3] - num1[gcd_xy] - num1[gcd_yz];
    long long g_z = num1[z] + num1[gcd_3] - num1[gcd_xz] - num1[gcd_yz];
    long long cnt = 0;
    cnt += num3[g_3];
    cnt += num2[g_3] * (g_xy + g_yz + g_xz + g_x + g_y + g_z);
    cnt += g_3 * (g_x * g_y + g_y * g_z + g_x * g_z + num2[g_xy] + num2[g_xz] +
                  num2[g_yz]);
    cnt += g_3 * ((g_xy + g_yz + g_xz) * (g_x + g_y + g_z));
    cnt += g_3 * (g_xy * g_xz + g_xz * g_yz + g_xy * g_yz);
    cnt += num2[g_xy] * (g_z + g_xz + g_yz) + num2[g_yz] * (g_x + g_xy + g_xz) +
           num2[g_xz] * (g_y + g_xy + g_yz);
    cnt += (g_x + g_y + g_z) * (g_xy * g_yz + g_xz * g_yz + g_xy * g_xz);
    cnt += (g_x * g_y) * (g_xz + g_yz) + (g_y * g_z) * (g_xy + g_xz) +
           (g_x * g_z) * (g_xy + g_yz);
    cnt += g_x * g_y * g_z;
    cnt += g_xy * g_yz * g_xz;
    printf("%d\n", (int)cnt);
  }
  return 0;
}
