#include <bits/stdc++.h>
int a[100005][130];
int vis[100005];
int num[3][3];
int Find(int k, int r, int w) {
  int l = 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (a[k][mid] < w)
      l = mid + 1;
    else
      r = mid - 1;
  }
  if (a[k][l] == w) return 1;
  return 0;
}
int main() {
  for (int i = 1; i <= 100000; i++) {
    int jsq = 0;
    for (int j = 1; j * j <= i; j++)
      if (i % j == 0) a[i][++jsq] = j;
    a[i][0] = jsq * 2;
    if (a[i][jsq] * a[i][jsq] == i) a[i][0]--;
    for (int j = 1; j <= jsq; j++) a[i][a[i][0] - j + 1] = i / a[i][j];
  }
  int t;
  scanf("%d", &t);
  while (t--) {
    num[0][1] = num[1][2] = num[0][2] = 0;
    int b[3];
    scanf("%d%d%d", &b[0], &b[1], &b[2]);
    for (int i = 0; i <= 2; i++) {
      for (int j = 1; j <= a[b[i]][0]; j++) {
        vis[a[b[i]][j]]++;
      }
    }
    int num3 = 0;
    for (int i = 1; i <= a[b[0]][0]; i++) {
      if (vis[a[b[0]][i]] == 3)
        num3++;
      else if (vis[a[b[0]][i]] == 2) {
        if (Find(b[1], a[b[1]][0], a[b[0]][i]))
          num[0][1]++;
        else
          num[0][2]++;
      }
      vis[a[b[0]][i]] = 0;
    }
    for (int i = 1; i <= 2; i++) {
      for (int j = 1; j <= a[b[i]][0]; j++) {
        if (vis[a[b[i]][j]] == 2) num[1][2]++;
        vis[a[b[i]][j]] = 0;
      }
    }
    int ans = a[b[1]][0] * a[b[0]][0] * a[b[2]][0];
    int num0 = a[b[0]][0] - num[0][1] - num[0][2] - num3;
    int num1 = a[b[1]][0] - num[0][1] - num[1][2] - num3;
    int num2 = a[b[2]][0] - num[1][2] - num[0][2] - num3;
    if (num[1][2] > 1) ans -= (a[b[0]][0]) * num[1][2] * (num[1][2] - 1) / 2;
    if (num[0][1] > 1) ans -= a[b[2]][0] * num[0][1] * (num[0][1] - 1) / 2;
    if (num[0][2] > 1) ans -= a[b[1]][0] * num[0][2] * (num[0][2] - 1) / 2;
    ans -= (num3 - 1) * (num3) / 2 * (num0 + num1 + num2);
    ans -= num3 * (num0 * num[1][2] + num1 * num[0][2] + num2 * num[0][1]);
    ans -= num[0][1] * num[0][2] * num[1][2];
    ans -= num3 *
           (num[0][1] * num[0][2] + num[0][2] * num[1][2] +
            num[0][1] * num[1][2]) *
           2;
    ans -= num3 * (num3 - 1) / 2 * (num[0][1] + num[1][2] + num[0][2]) * 3;
    if (num3 > 1) ans -= num3 * (num3 - 2) * (num3 - 1) / 6 * 5;
    ans -= num3 * (num[0][1] + num[1][2] + num[0][2]);
    ans -= num3 * (num3 - 1) / 2 * 4;
    printf("%d\n", ans);
  }
  return 0;
}
