#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
long long cnt[N];
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
long long sum2(long long n) { return n * (n + 1) / 2; }
long long sum3(long long n) { return n * (n + 1) * (n + 2) / 6; }
bool cancover(int a, int b, int c) {
  return ((a & 1) && ((b & 2) && (c & 4) || (b & 4) && (c & 2))) ||
         ((a & 2) && ((b & 1) && (c & 4) || (b & 4) && (c & 1))) ||
         ((a & 4) && ((b & 2) && (c & 1) || (b & 1) && (c & 2)));
}
int main() {
  int t;
  scanf("%d", &t);
  for (int x = 1; x < N; ++x)
    for (int y = x; y < N; y += x) ++cnt[y];
  while (t--) {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    long long ans = 0, tab, tbc, tac, tmp;
    tab = cnt[gcd(a, b)];
    tbc = cnt[gcd(b, c)];
    tac = cnt[gcd(a, c)];
    tmp = cnt[gcd(gcd(a, b), c)];
    static long long st[8];
    st[1] = cnt[a] - tab - tac + tmp;
    st[2] = cnt[b] - tbc - tab + tmp;
    st[3] = tab - tmp;
    st[4] = cnt[c] - tac - tbc + tmp;
    st[5] = tac - tmp;
    st[6] = tbc - tmp;
    st[7] = tmp;
    long long delta = 0;
    for (int sa = 1; sa < 8; ++sa) {
      for (int sb = sa; sb < 8; ++sb) {
        for (int sc = sb; sc < 8; ++sc) {
          if (!cancover(sa, sb, sc)) continue;
          if (sa == sb) {
            if (sa == sc) {
              delta = sum3(st[sa]);
            } else
              delta = sum2(st[sa]) * st[sc];
          } else {
            if (sa == sc) {
              delta = st[sb] * sum2(st[sa]);
            } else {
              if (sb == sc) {
                delta = st[sa] * sum2(st[sb]);
              } else
                delta = st[sa] * st[sb] * st[sc];
            }
          }
          ans += delta;
        }
      }
    }
    printf("%lld\n", ans);
  }
  return 0;
}
