#include <bits/stdc++.h>
using namespace std;
const int MAXM = 1e5 + 5;
int factor[MAXM][128], cnt_factor[MAXM];
int gcd(int a, int b) {
  if (b == 0) return a;
  return gcd(b, a % b);
}
long long g(int A, int B, int C) {
  int val[6][3] = {{A, B, C}, {A, C, B}, {B, A, C},
                   {B, C, A}, {C, A, B}, {C, B, A}};
  long long ans = 0;
  for (int i = 1; i < (1 << 6); i++) {
    int cur[3] = {0, 0, 0}, cnt = 0;
    for (int j = 0; j < 6; j++)
      if (i >> j & 1) {
        cnt++;
        cur[0] = gcd(cur[0], val[j][0]);
        cur[1] = gcd(cur[1], val[j][1]);
        cur[2] = gcd(cur[2], val[j][2]);
      }
    long long add =
        (long long)cnt_factor[cur[0]] * cnt_factor[cur[1]] * cnt_factor[cur[2]];
    add += cnt_factor[gcd(cur[0], cur[1])] * cnt_factor[cur[2]] * 3;
    if (cnt & 1)
      ans += add;
    else
      ans -= add;
  }
  ans += 2 * cnt_factor[gcd(A, gcd(B, C))];
  return ans / 6;
}
int buf[150];
void merge_sort(int *arr, int l, int r) {
  if (l < r) {
    int mid = (l + r) / 2;
    merge_sort(arr, l, mid);
    merge_sort(arr, mid + 1, r);
    int cnt_buf = 0;
    int i = l, j = mid + 1;
    while (i <= mid && j <= r) {
      if (arr[i] <= arr[j])
        buf[cnt_buf++] = arr[i++];
      else
        buf[cnt_buf++] = arr[j++];
    }
    while (i <= mid) buf[cnt_buf++] = arr[i++];
    while (j <= r) buf[cnt_buf++] = arr[j++];
    for (int k = 0; k < cnt_buf; k++) arr[l + k] = buf[k];
  }
}
int main() {
  for (int i = 1; i < MAXM; i++) {
    for (int j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        factor[i][cnt_factor[i]++] = j;
        if (j != i / j) factor[i][cnt_factor[i]++] = i / j;
      }
    }
    merge_sort(factor[i], 0, cnt_factor[i] - 1);
  }
  int n;
  scanf("%d", &n);
  while (n--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    printf("%lld\n", g(a, b, c));
  }
  return 0;
}
