#include <bits/stdc++.h>
using namespace std;
#pragma comment(linker, "/STACK:102400000,102400000")
long long mul(long long a, long long b) { return (a * b) % (1000000007); }
long long add(long long a, long long b) { return (a + b) % (1000000007); }
long long sub(long long a, long long b) {
  return ((a - b) % (1000000007) + (1000000007)) % (1000000007);
}
void upd(long long &a, long long b) {
  a = (a % (1000000007) + b % (1000000007)) % (1000000007);
}
inline int read() {
  int x = 0, f = 1;
  char ch = getchar();
  while (!isdigit(ch)) {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (isdigit(ch)) {
    x = x * 10 + ch - '0';
    ch = getchar();
  }
  return x * f;
}
long long a, b, c;
int sz[(100001)];
vector<int> yinzi[(100001)];
long long gcd(long long a, long long b) { return (!b) ? a : gcd(b, a % b); }
inline long long get(int x, int y, int z) { return sz[x] * sz[z] * sz[y]; }
inline long long get(int x, int z) { return sz[x] * sz[z]; }
long long p, q, r;
int z[10][10] = {};
void dfs(int i, int a, int b, int c, int k) {
  if (i > 6) {
    if (a) {
      long long f = (long long)sz[a] * sz[b] * sz[c];
      long long g = get(gcd(a, b), c) + get(gcd(b, c), a) + get(gcd(a, c), b);
      long long ga = gcd(c, gcd(a, b));
      long long h = sz[ga];
      g -= 3 * h, f -= g + h;
      p += f * k;
      q += g * k;
      r += h * k;
    }
    return;
  }
  dfs(i + 1, a, b, c, k);
  dfs(i + 1, gcd(a, z[i][1]), gcd(b, z[i][2]), gcd(c, z[i][3]), -k);
}
void work(int a, int b, int c) {
  dfs(1, 0, 0, 0, -1);
  int p[5], per[5];
  p[1] = a, p[2] = b, p[3] = c;
  per[1] = 1, per[2] = 2, per[3] = 3;
  int ii = 1;
  do {
    for (int i = 1; i <= 3; i++) z[ii][i] = p[per[i]];
    ++ii;
  } while (next_permutation(per + 1, per + 4));
  ::p = 0;
  q = r = 0;
  dfs(1, 0, 0, 0, -1);
  printf("%I64d\n", ::p / 6 + q / 3 + r);
}
int main() {
  int n = 1e5;
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) sz[j]++;
  }
  int T = read();
  while (T--) {
    a = read(), b = read(), c = read();
    work(a, b, c);
  }
  return 0;
}
