#include <bits/stdc++.h>
using namespace std;
long long cnt[8];
int last[100000 + 5];
struct masks {
  masks(int ii, int jj, int kk) {
    i = ii;
    j = jj;
    k = kk;
  }
  int i, j, k;
};
vector<masks> acceptables;
long long ncr(long long n, long long r) {
  if (r == 2) {
    return (n * (n - 1)) / 2;
  }
  if (r == 3) {
    return (n * (n - 1) * (n - 2)) / 6;
  }
  return 0;
}
int main() {
  for (int i = 0; i < 8; i++) {
    for (int j = i; j < 8; j++) {
      for (int k = j; k < 8; k++) {
        int perm[3] = {i, j, k};
        bool acceptable(false);
        do {
          if ((perm[0] & (1 << 0)) != 0 && (perm[1] & (1 << 1)) != 0 &&
              (perm[2] & (1 << 2)) != 0) {
            acceptable = true;
            break;
          }
        } while (next_permutation(perm, perm + 3));
        if (acceptable) {
          acceptables.push_back(masks(i, j, k));
        }
      }
    }
  }
  int test;
  scanf("%d", &test);
  for (int cas = 1; cas <= test; cas++) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    for (int i = 0; i < 8; i++) {
      cnt[i] = 0;
    }
    std::vector<int> divs;
    for (int i = 1; i * i <= 100000; i++) {
      if (a % i == 0) {
        divs.push_back(i);
        divs.push_back(a / i);
      }
      if (b % i == 0) {
        divs.push_back(i);
        divs.push_back(b / i);
      }
      if (c % i == 0) {
        divs.push_back(i);
        divs.push_back(c / i);
      }
    }
    for (int x : divs) {
      if (last[x] == cas) {
        continue;
      }
      int bt(0);
      if (a % x == 0) {
        bt += (1 << 0);
      }
      if (b % x == 0) {
        bt += (1 << 1);
      }
      if (c % x == 0) {
        bt += (1 << 2);
      }
      cnt[bt]++;
      last[x] = cas;
    }
    long long ans(0);
    for (masks m : acceptables) {
      int i = m.i;
      int j = m.j;
      int k = m.k;
      if (i == j && j == k) {
        ans += ncr(cnt[i] + 2, 3);
      } else if (i == j) {
        ans += ncr(cnt[i] + 1, 2) * cnt[k];
      } else if (j == k) {
        ans += cnt[i] * ncr(cnt[j] + 1, 2);
      } else {
        ans += cnt[i] * cnt[j] * cnt[k];
      }
    }
    printf("%I64d\n", ans);
  }
  return 0;
}
