#include <bits/stdc++.h>
using namespace std;
int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x % y);
}
long long num[100010];
void init() {
  for (int i = 1; i <= 100000; i++) {
    for (int j = i; j <= 100000; j += i) num[j]++;
  }
}
long long s[10];
vector<int> p[3];
long long c3(long long x) {
  if (x <= 2) return 0;
  return x * (x - 1) / 2 * (x - 2) / 3;
}
long long c2(long long x) {
  if (x <= 1) return 0;
  return x * (x - 1) / 2;
}
long long solve(int x, int y, int z) {
  if (x > y) swap(x, y);
  if (x > z) swap(x, z);
  if (y > z) swap(y, z);
  if (x == y && y == z) return c3(s[x]) + c2(s[x]) * 2 + s[x];
  if (x == y) return (s[y] + c2(s[y])) * s[z];
  if (y == z) return (s[y] + c2(s[y])) * s[x];
  return s[x] * s[y] * s[z];
}
set<pair<int, pair<int, int> > > ooxx;
set<pair<int, pair<int, int> > >::iterator ll;
void in(int x, int y, int z) {
  if (x > y) swap(x, y);
  if (x > z) swap(x, z);
  if (y > z) swap(y, z);
  ooxx.insert(make_pair(x, make_pair(y, z)));
}
int main() {
  init();
  p[0].push_back(1);
  p[0].push_back(2);
  p[0].push_back(3);
  p[0].push_back(4);
  p[1].push_back(2);
  p[1].push_back(3);
  p[1].push_back(5);
  p[1].push_back(6);
  p[2].push_back(3);
  p[2].push_back(4);
  p[2].push_back(6);
  p[2].push_back(7);
  for (int i = 0; i < 4; i++)
    for (int j = 0; j < 4; j++)
      for (int k = 0; k < 4; k++) in(p[0][i], p[1][j], p[2][k]);
  int cas;
  scanf("%d", &cas);
  for (int cc = 1; cc <= cas; cc++) {
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    s[3] = num[gcd(a, gcd(b, c))];
    s[2] = num[gcd(a, b)] - s[3];
    s[4] = num[gcd(a, c)] - s[3];
    s[6] = num[gcd(b, c)] - s[3];
    s[1] = num[a] - s[2] - s[3] - s[4];
    s[5] = num[b] - s[2] - s[3] - s[6];
    s[7] = num[c] - s[3] - s[4] - s[6];
    long long ans = 0;
    for (ll = ooxx.begin(); ll != ooxx.end(); ll++)
      ans += solve((*ll).first, (*ll).second.first, (*ll).second.second);
    cout << ans << endl;
  }
  return 0;
}
