#include <bits/stdc++.h>
using namespace std;
const int M = (int)1e5 + 5;
vector<int> ps[M];
void init() {
  for (int i = 1; i < M; i++)
    for (int j = i; j < M; j += i) ps[j].push_back(i);
}
int ask(int x, int y) {
  int re = 0;
  for (int i = 0, j = 0, upi = ps[x].size(), upj = ps[y].size();
       i < upi && j < upj;) {
    if (ps[x][i] == ps[y][j])
      re++, i++, j++;
    else if (ps[x][i] > ps[y][j])
      j++;
    else
      i++;
  }
  return re;
}
int ask(int x, int y, int z) {
  int re = 0;
  for (int i = 0, j = 0, k = 0, mi, upi = ps[x].size(), upj = ps[y].size(),
           upk = ps[z].size();
       i < upi && j < upj && k < upk;) {
    if (ps[x][i] == ps[y][j] && ps[x][i] == ps[z][k])
      re++, i++, j++, k++;
    else {
      mi = min(min(ps[x][i], ps[y][j]), ps[z][k]);
      if (mi == ps[x][i])
        i++;
      else if (mi == ps[y][j])
        j++;
      else
        k++;
    }
  }
  return re;
}
int x, y, z, xy, yz, zx, xyz;
void solve() {
  scanf("%d %d %d", &x, &y, &z);
  xy = ask(x, y), yz = ask(y, z), zx = ask(z, x);
  xyz = ask(x, y, z);
  printf("%I64d\n",
         (long long)ps[x].size() * ps[y].size() * ps[z].size() -
             (long long)xy * (xy - 1) / 2 * ps[z].size() -
             (long long)yz * (yz - 1) / 2 * ps[x].size() -
             (long long)zx * (zx - 1) / 2 * ps[y].size() -
             (long long)(xy - xyz) * (yz - xyz) * (zx - xyz) +
             (long long)xyz * (xyz - 1) / 2 * (xy + yz + zx - xyz - xyz - xyz) +
             (long long)xyz * (xyz - 1) * (xyz - 2) / 6 * 4 +
             (long long)xyz * (xyz - 1));
}
int main() {
  init();
  int cas;
  scanf("%d", &cas);
  while (cas--) solve();
  return 0;
}
