#include <bits/stdc++.h>
using namespace std;
vector<int> divs[100005];
long long int gcd(long long int a, long long int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
void solve() {
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);
  long long int k, x = 0, y12 = 0, y23 = 0, y31 = 0, z1 = 0, z2 = 0, z3 = 0;
  long long int i, j;
  for (auto it : divs[a]) {
    if (b % it == 0 && c % it == 0)
      x++;
    else if (b % it == 0)
      y12++;
    else if (c % it == 0)
      y31++;
    else
      z1++;
  }
  for (auto it : divs[b]) {
    if (a % it == 0) continue;
    if (c % it == 0)
      y23++;
    else
      z2++;
  }
  for (auto it : divs[c]) {
    if ((a % it == 0) || (b % it == 0)) continue;
    z3++;
  }
  long long int ans = 0;
  long long int zzz, zzy, zzx, zxy, zyy, zxx, xxx, xxy, xyy, yyy;
  zzz = z1 * z2 * z3;
  zzy = z1 * z2 * (y31 + y23) + z2 * z3 * (y12 + y31) + z3 * z1 * (y23 + y12);
  zzx = x * (z1 * z2 + z2 * z3 + z3 * z1);
  zxy = z1 * x * (y23 + y31 + y12) + z2 * x * (y31 + y23 + y12) +
        z3 * x * (y23 + y12 + y31);
  long long int yrep = y12 * y23 + y23 * y31 + y31 * y12;
  zyy = z1 * (yrep + (y23 * (y23 + 1)) / 2);
  zyy += z2 * (yrep + (y31 * (y31 + 1)) / 2);
  zyy += z3 * (yrep + (y12 * (y12 + 1)) / 2);
  zxx = (x * (x - 1) * (z1 + z2 + z3)) / 2 + x * (z1 + z2 + z3);
  xxx = (x * (x - 1) * (x - 2)) / 6 + x * (x - 1) + x;
  xxy = ((x * (x - 1)) / 2 + x) * (y12 + y23 + y31);
  xyy = x * ((y12 * (y12 + 1)) / 2 + (y31 * (y31 + 1)) / 2 +
             (y23 * (y23 + 1)) / 2 + y12 * y23 + y12 * y31 + y23 * y31);
  yyy = (y12 * (y12 + 1) * (y31 + y23)) / 2;
  yyy += (y23 * (y23 + 1) * (y12 + y31)) / 2;
  yyy += (y31 * (y31 + 1) * (y12 + y23)) / 2;
  yyy += y12 * y23 * y31;
  ans = zzz + zzy + zzx + zyy + zxx + zxy + xxx + xxy + xyy + yyy;
  printf("%lld\n", ans);
}
void pre() {
  for (int i = 1; i <= 100000; i++) {
    for (int j = 1; j * j <= i; j++) {
      if (i % j != 0) continue;
      divs[i].push_back(j);
      if (j != i / j) divs[i].push_back(i / j);
    }
  }
}
int main() {
  pre();
  int t, i, j;
  cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}
