#include <bits/stdc++.h>
using namespace std;
const int M = 1e5 + 5;
vector<int> factors[M];
void init() {
  for (int j = 1; j < M; j++) {
    for (int k = j; k < M; k += j) {
      factors[k].push_back(j);
    }
  }
}
int sum[10];
int ra[] = {0, 1, 2, 3};
int rb[] = {1, 3, 4, 5};
int rc[] = {2, 3, 5, 6};
long long C(int x, int y) {
  if (y == 1) return x;
  if (y == 2) return 1LL * x * (x - 1) / 2;
  if (y == 3) return 1LL * x * (x - 1) * (x - 2) / 6;
}
int main() {
  init();
  set<multiset<int>> st;
  for (auto x : ra) {
    for (auto y : rb) {
      for (auto z : rc) {
        multiset<int> stt;
        stt.insert(x);
        stt.insert(y);
        stt.insert(z);
        st.insert(stt);
      }
    }
  }
  vector<vector<int>> ini;
  for (auto x : st) {
    vector<int> now;
    for (auto y : x) {
      now.push_back(y);
    }
    ini.push_back(now);
  }
  int T;
  scanf("%d", &T);
  while (T--) {
    memset(sum, 0, sizeof(sum));
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    for (auto x : factors[a]) {
      if (b % x == 0 && c % x == 0)
        sum[3]++;
      else if (b % x == 0)
        sum[1]++;
      else if (c % x == 0)
        sum[2]++;
      else
        sum[0]++;
    }
    for (auto x : factors[b]) {
      if (c % x == 0 && a % x) sum[5]++;
    }
    sum[4] = factors[b].size() - sum[1] - sum[5] - sum[3];
    sum[6] = factors[c].size() - sum[2] - sum[5] - sum[3];
    long long ans = 0;
    for (auto zz : ini) {
      int x = zz[0], y = zz[1], z = zz[2];
      if (x == y && y == z) {
        ans += C(sum[x], 3) + C(sum[x], 2) * 2 + C(sum[x], 1);
      } else if (x == y) {
        ans += (C(sum[x], 1) + C(sum[x], 2)) * sum[z];
      } else if (x == z) {
        ans += (C(sum[x], 1) + C(sum[x], 2)) * sum[y];
      } else if (y == z) {
        ans += (C(sum[y], 1) + C(sum[y], 2)) * sum[x];
      } else {
        ans += sum[x] * sum[y] * sum[z];
      }
    }
    printf("%I64d\n", ans);
  }
}
