#include <bits/stdc++.h>
using namespace std;
int combination(int n, int k) {
  if (k > n) return 0;
  if (k == 1) return n;
  if (k == 2) return n * (n - 1) / 2;
  return n * (n - 1) * (n - 2) / 6;
}
int primes[] = {2,   3,   5,   7,   11,  13,  17,  19,  23,  29,  31,  37,
                41,  43,  47,  53,  59,  61,  67,  71,  73,  79,  83,  89,
                97,  101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151,
                157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223,
                227, 229, 233, 239, 241, 251, 257, 263, 269, 271, 277, 281,
                283, 293, 307, 311, 313, 317, 331, 337, 347, 349, 353, 359,
                367, 373, 379, 383, 389, 397};
int cnt_div(int n) {
  int ans = 1;
  for (int i = 0; i < 78; i++) {
    int temp = 1;
    while (n % primes[i] == 0) {
      n /= primes[i];
      temp++;
    }
    ans *= temp;
  }
  if (n != 1) ans *= 2;
  return ans;
}
int gcd(int m, int n) {
  if (n == 0)
    return m;
  else
    return gcd(n, m % n);
}
int main() {
  int t, a, b, c;
  cin >> t;
  while (t--) {
    scanf("%d%d%d", &a, &b, &c);
    int ab = gcd(max(a, b), min(a, b)), bc = gcd(max(c, b), min(c, b)),
        ac = gcd(max(a, c), min(a, c));
    int abc = gcd(max(ab, bc), min(ab, bc));
    int cnt_ab = cnt_div(ab), cnt_ac = cnt_div(ac), cnt_bc = cnt_div(bc),
        cnt_abc = cnt_div(abc);
    cnt_ab -= cnt_abc;
    cnt_ac -= cnt_abc;
    cnt_bc -= cnt_abc;
    a = cnt_div(a) - cnt_ab - cnt_ac - cnt_abc;
    b = cnt_div(b) - cnt_ab - cnt_bc - cnt_abc;
    c = cnt_div(c) - cnt_bc - cnt_ac - cnt_abc;
    long long ans = 0;
    ans += a * b * (c + cnt_bc + cnt_ac + cnt_abc);
    ans += a * c * (cnt_ab + cnt_bc + cnt_abc);
    ans += c * b * (cnt_ab + cnt_ac + cnt_abc);
    ans += (a + b + c) * (cnt_ab * cnt_ac);
    ans += (a + b + c) * (cnt_ab * cnt_bc);
    ans += (a + b + c) * (cnt_ab * cnt_abc);
    ans += (a + b + c) * (cnt_bc * cnt_ac);
    ans += (a + b + c) * (cnt_ac * cnt_abc);
    ans += (a + b + c) * (cnt_bc * cnt_abc);
    ans += a * (cnt_bc + cnt_abc);
    ans += a * (combination(cnt_bc, 2) + combination(cnt_abc, 2));
    ans += b * (cnt_ac + cnt_abc);
    ans += b * (combination(cnt_ac, 2) + combination(cnt_abc, 2));
    ans += c * (cnt_ab + cnt_abc);
    ans += c * (combination(cnt_ab, 2) + combination(cnt_abc, 2));
    ans += cnt_ab * cnt_ac * cnt_bc;
    ans += cnt_abc * cnt_ac * cnt_bc;
    ans += cnt_ab * cnt_abc * cnt_bc;
    ans += cnt_ab * cnt_ac * cnt_abc;
    ans += combination(cnt_ac, 2) * combination(cnt_ab, 1);
    ans += combination(cnt_ac, 1) * combination(cnt_ab, 2);
    ans += combination(cnt_ac, 1) * combination(cnt_ab, 1) * 2;
    ans += combination(cnt_ac, 2) * combination(cnt_bc, 1);
    ans += combination(cnt_ac, 1) * combination(cnt_bc, 2);
    ans += combination(cnt_ac, 1) * combination(cnt_bc, 1) * 2;
    ans += combination(cnt_ac, 2) * combination(cnt_abc, 1);
    ans += combination(cnt_ac, 1) * combination(cnt_abc, 2);
    ans += combination(cnt_ac, 1) * combination(cnt_abc, 1) * 2;
    ans += combination(cnt_ab, 2) * combination(cnt_bc, 1);
    ans += combination(cnt_ab, 1) * combination(cnt_bc, 2);
    ans += combination(cnt_ab, 1) * combination(cnt_bc, 1) * 2;
    ans += combination(cnt_ab, 2) * combination(cnt_abc, 1);
    ans += combination(cnt_ab, 1) * combination(cnt_abc, 2);
    ans += combination(cnt_ab, 1) * combination(cnt_abc, 1) * 2;
    ans += combination(cnt_bc, 2) * combination(cnt_abc, 1);
    ans += combination(cnt_bc, 1) * combination(cnt_abc, 2);
    ans += combination(cnt_bc, 1) * combination(cnt_abc, 1) * 2;
    ans += combination(cnt_abc, 1);
    ans += combination(cnt_abc, 2) * 2;
    ans += combination(cnt_abc, 3);
    cout << ans << endl;
  }
  return 0;
}
