#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 10;
int num[N];
int a[10][5];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
void init() {
  for (int i = 1; i < N; i++) {
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        num[i]++;
        if (j * j < i) num[i]++;
      }
    }
  }
  int cnt = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j) continue;
      a[cnt][0] = i;
      a[cnt][1] = j;
      a[cnt++][2] = 3 - i - j;
    }
  }
}
void solve() {
  long long ans1 = 0, ans2 = 0;
  int x, y, z;
  scanf("%d%d%d", &x, &y, &z);
  int g[10];
  g[1] = num[x];
  g[2] = num[y];
  g[4] = num[z];
  g[3] = num[gcd(x, y)];
  g[5] = num[gcd(x, z)];
  g[6] = num[gcd(y, z)];
  g[7] = num[gcd(x, gcd(y, z))];
  int b[3];
  int cnt;
  for (int s = 1; s < (1 << 6); s++) {
    cnt = 0;
    for (int i = 0; i < 3; i++) b[i] = 0;
    for (int i = 0; i < 6; i++) {
      if (s & (1 << i)) {
        cnt++;
        for (int j = 0; j < 3; j++) b[j] |= (1 << a[i][j]);
      }
    }
    if (cnt & 1)
      cnt = 1;
    else
      cnt = -1;
    ans1 += cnt * g[b[0]] * g[b[1]] * g[b[2]];
    ans2 += cnt * g[b[0] | b[1]] * g[b[2]];
  }
  printf("%lld\n", (ans1 + ans2 * 3 + g[7] * 2) / 6);
}
int main() {
  int t;
  init();
  scanf("%d", &t);
  for (int i = 0; i < t; i++) solve();
  return 0;
}
