#include <bits/stdc++.h>
using namespace std;
int n, ans, a, b, c, num[100005], two_same[200], three_same[200], t[8];
void prework() {
  for (int i = 1; i <= 100000; ++i) {
    for (int j = i; j <= 100000; j += i) {
      num[j]++;
    }
  }
  for (int i = 1; i <= 150; ++i) {
    two_same[i] = i * (i + 1) / 2;
    three_same[i] = three_same[i - 1] + two_same[i];
  }
}
int gcd(int x, int y) { return !y ? x : gcd(y, x % y); }
bool subcheck(int x, int y, int z) { return (x & 1) && (y & 2) && (z & 4); }
bool check(int x, int y, int z) {
  return subcheck(x, y, z) || subcheck(x, z, y) || subcheck(y, x, z) ||
         subcheck(y, z, x) || subcheck(z, x, y) || subcheck(z, y, x);
}
int main() {
  scanf("%d", &n);
  prework();
  for (int i = 1; i <= n; ++i) {
    scanf("%d%d%d", &a, &b, &c);
    int ab = gcd(a, b), bc = gcd(b, c), ac = gcd(a, c), abc = gcd(ab, c);
    ans = 0;
    t[7] = num[abc];
    t[3] = num[ab] - num[abc];
    t[6] = num[bc] - num[abc];
    t[5] = num[ac] - num[abc];
    t[1] = num[a] - num[ab] - num[ac] + num[abc];
    t[2] = num[b] - num[ab] - num[bc] + num[abc];
    t[4] = num[c] - num[ac] - num[bc] + num[abc];
    for (int i = 1; i <= 7; ++i) {
      for (int j = i; j <= 7; ++j) {
        for (int k = j; k <= 7; ++k) {
          if (!check(i, j, k)) continue;
          if (i == j && j == k)
            ans += three_same[t[i]];
          else if (i == j)
            ans += two_same[t[i]] * t[k];
          else if (i == k)
            ans += two_same[t[i]] * t[j];
          else if (j == k)
            ans += two_same[t[j]] * t[i];
          else
            ans += t[i] * t[j] * t[k];
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
