#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
bool can[8][8][8];
int a, b, c, vis[N], lol, freq[8], ans;
vector<int> v[N];
void add(int x) {
  int msk = 0;
  for (auto i : v[x]) {
    if (vis[i] == lol) continue;
    vis[i] = lol;
    msk = 0;
    if (!(a % i)) msk = 1;
    if (!(b % i)) msk += 2;
    if (!(c % i)) msk += 4;
    freq[msk]++;
  }
}
int main() {
  for (int i = 1; i < N; i++)
    for (int j = i; j < N; j += i) v[j].push_back(i);
  for (int i = 1; i < 8; i++)
    for (int j = 1; j < 8; j++)
      for (int k = 1; k < 8; k++) {
        vector<int> v;
        v.push_back(i);
        v.push_back(j);
        v.push_back(k);
        sort(v.begin(), v.end());
        do {
          if (v[0] & 1 && v[1] & 2 && v[2] & 4) can[i][j][k] = 1;
        } while (next_permutation(v.begin(), v.end()));
      }
  int T;
  cin >> T;
  while (T--) {
    lol++;
    cin >> a >> b >> c;
    memset(freq, 0, sizeof freq);
    add(a);
    add(b);
    add(c);
    ans = 0;
    for (int i = 1; i < 8; i++)
      for (int j = i; j < 8; j++)
        for (int k = j; k < 8; k++) {
          if (!can[i][j][k]) continue;
          if (i == j && j == k)
            ans += freq[i] * (freq[i] + 1) * (freq[i] + 2) / 6;
          else if (i == j)
            ans += freq[i] * (freq[i] + 1) * freq[k] / 2;
          else if (j == k)
            ans += freq[j] * (freq[j] + 1) * freq[i] / 2;
          else if (i == k)
            ans += freq[i] * (freq[i] + 1) * freq[j] / 2;
          else
            ans += freq[i] * freq[j] * freq[k];
        }
    cout << ans << endl;
  }
}
