#include <bits/stdc++.h>
using namespace std;
int intcmp(const void *v1, const void *v2) { return *(int *)v1 - *(int *)v2; }
int yzcnt[100010];
void init() {
  for (int i = 1; i < 100001; i++) yzcnt[i]++;
  for (int i = 2; i < 100001; i++) {
    for (int j = 1; j < 100000 / i + 1; j++) {
      if (i * j < 100001) {
        yzcnt[i * j]++;
      }
    }
  }
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long calc(long long *v1, long long *v2, long long *v3) {
  if (v1 == v2 && v2 == v3) {
    return (*v1) * (*v1 + 1) * (*v1 + 2) / 6;
  }
  if (v1 == v2) {
    return (*v3) * ((*v1 + 1) * (*v1) / 2);
  }
  if (v2 == v3) {
    return (*v1) * ((*v2 + 1) * (*v2) / 2);
  }
  if (v3 == v1) {
    return (*v2) * ((*v3 + 1) * (*v3) / 2);
  }
  return (*v1) * (*v2) * (*v3);
}
int ec(int a, int b, int c) { return c + 7 * (b + 7 * a); }
int main() {
  init();
  int t;
  cin >> t;
  while (t-- > 0) {
    int v[3];
    scanf("%d %d %d", v, v + 1, v + 2);
    int gab = gcd(v[0], v[1]);
    int gbc = gcd(v[1], v[2]);
    int gca = gcd(v[2], v[0]);
    int gabc = gcd(gab, v[2]);
    long long a = yzcnt[v[0]] - yzcnt[gab] - yzcnt[gca] + yzcnt[gabc];
    long long b = yzcnt[v[1]] - yzcnt[gbc] - yzcnt[gab] + yzcnt[gabc];
    long long c = yzcnt[v[2]] - yzcnt[gca] - yzcnt[gbc] + yzcnt[gabc];
    long long ab = yzcnt[gab] - yzcnt[gabc];
    long long bc = yzcnt[gbc] - yzcnt[gabc];
    long long ca = yzcnt[gca] - yzcnt[gabc];
    long long abc = yzcnt[gabc];
    long long *slotA[] = {&a, &ab, &ca, &abc};
    long long *slotB[] = {&b, &bc, &ab, &abc};
    long long *slotC[] = {&c, &ca, &bc, &abc};
    int slotMaskA[] = {0, 3, 5, 6};
    int slotMaskB[] = {1, 4, 3, 6};
    int slotMaskC[] = {2, 5, 4, 6};
    bool masks[7 * 7 * 7];
    for (int i = 0; i < 7 * 7 * 7; i++) {
      masks[i] = false;
    }
    long long ans0 = 0;
    for (int i = 0; i < 4; i++) {
      for (int j = 0; j < 4; j++) {
        for (int k = 0; k < 4; k++) {
          int maskarr[] = {slotMaskA[i], slotMaskB[j], slotMaskC[k]};
          sort(maskarr, maskarr + 3);
          int code = ec(maskarr[0], maskarr[1], maskarr[2]);
          if (!masks[code]) {
            masks[code] = true;
            ans0 += calc(slotA[i], slotB[j], slotC[k]);
          }
        }
      }
    }
    long long ans =
        a * b * c + a * b * ca + a * b * bc + a * b * abc + a * ab * c +
        a * ab * ca + a * ab * bc + a * ab * abc + a * bc * c + a * bc * ca +
        a * bc * abc + a * (bc * (bc + 1) / 2) + a * abc * c + a * abc * ca +
        a * (abc * (abc + 1) / 2) + ab * b * c + ab * b * ca + ab * b * bc +
        ab * b * abc + ab * bc * c + ab * bc * ca + ab * bc * abc +
        ab * (bc * (bc + 1) / 2) + ab * abc * c + ab * abc * ca + ca * b * c +
        ca * b * bc + ca * b * abc + ca * ab * c + ca * bc * c + ca * bc * abc +
        ca * abc * c + abc * b * c + abc * b * bc + abc * bc * c +
        abc * (abc - 1) * (abc - 2) / 6 + (ab * (ab + 1) / 2) * c +
        (ab * (ab + 1) / 2) * ca + (ab * (ab + 1) / 2) * bc +
        (ab * (ab + 1) / 2) * abc + (abc + abc * (abc + 1) / 2) * ab +
        (ca * (ca + 1) / 2) * b + (ca * (ca + 1) / 2) * ab +
        (ca * (ca + 1) / 2) * bc + (bc * (bc + 1) / 2) * ca +
        (ca * (ca + 1) / 2) * abc + (abc * (abc + 1) / 2) * ca +
        (abc * (abc + 1) / 2) * b + (bc * (bc + 1) / 2) * abc +
        (abc * (abc + 1) / 2) * bc + (abc * (abc + 1) / 2) * c + abc * abc;
    printf("%lld", ans0);
    printf("\n");
  }
  return 0;
}
