#include <bits/stdc++.h>
using namespace std;
int d[100005], b[5], t[15];
int cnt[15];
set<int> S;
int a[5], res;
vector<int> v[100005];
int u;
inline void solve(vector<int> &v) {
  if (u == 1) {
    int g = cnt[7];
    res += g * (g + 1) * (g + 2) / 6;
  } else if (u == 2) {
    int k1, k2, k3;
    for (int i = 0; i <= 2; i++) {
      for (int j = i + 1; j <= 2; j++) {
        if (v[i] == v[j]) {
          k1 = i;
          k2 = j;
          k3 = 3 - k1 - k2;
          break;
        }
      }
    }
    int g = cnt[v[k1]];
    t[u] += g * (g + 1) / 2 * cnt[v[k3]];
  } else {
    t[u] += cnt[v[0]] * cnt[v[1]] * cnt[v[2]];
  }
}
vector<int> V;
bool dd[100005], ee[100005];
int main() {
  ios::sync_with_stdio(0);
  cin.tie(NULL);
  for (int i = 1; i <= 100000; i++) {
    for (int j = 1; j <= 100000 / i; j++) {
      d[i * j]++;
      v[i * j].push_back(i);
    }
  }
  int te;
  cin >> te;
  for (int z = 1; z <= te; z++) {
    for (int i = 0; i <= 7; i++) cnt[i] = t[i] = 0;
    res = 0;
    for (int i = 0; i <= 2; i++) cin >> a[i];
    int T = 0;
    for (int i = 0; i <= 2; i++) {
      for (auto j : v[a[i]]) {
        if (dd[j]) continue;
        dd[j] = 1;
        T = 0;
        for (int kk = 0; kk <= 2; kk++) {
          if (!(a[kk] % j)) {
            T += (1 << kk);
          }
        }
        cnt[T]++;
      }
    }
    for (int t1 = 1; t1 <= 7; t1++) {
      for (int t2 = 1; t2 <= 7; t2++) {
        for (int t3 = 1; t3 <= 7; t3++) {
          V.clear();
          V.push_back(t1);
          V.push_back(t2);
          V.push_back(t3);
          ee[t1] = 1;
          u = 1;
          if (!ee[t2]) {
            ee[t2] = 1;
            u++;
          }
          if (!ee[t3]) {
            ee[t3] = 1;
            u++;
          }
          ee[t1] = ee[t2] = ee[t3] = 0;
          bool q = 1;
          for (int j = 0; j <= 2; j++) b[j] = j;
          do {
            q = 1;
            for (int j = 0; j <= 2; j++) {
              if (!(V[b[j]] & (1 << j))) {
                q = 0;
                continue;
              }
            }
            if (q) {
              solve(V);
              break;
            }
          } while (next_permutation(b, b + 3));
        }
      }
    }
    res += t[2] / 3 + t[3] / 6;
    cout << res << endl;
    for (int i = 0; i <= 2; i++) {
      for (auto j : v[a[i]]) dd[j] = 0;
    }
  }
  return 0;
}
