#include <bits/stdc++.h>
using namespace std;
vector<int> factors[100001];
int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  int i, n, j, k, a, b, c, t, x, y, z;
  for (i = 1; i <= 100000; i++) {
    for (j = i; j <= 100000; j += i) factors[j].push_back(i);
  }
  int As[4] = {1, 4, 6, 7}, Bs[4] = {3, 5, 6, 7}, Cs[4] = {2, 4, 5, 7};
  set<vector<int> > combis;
  for (i = 0; i < 4; i++)
    for (j = 0; j < 4; j++)
      for (k = 0; k < 4; k++) {
        vector<int> temp{As[i], Bs[j], Cs[k]};
        sort((temp).begin(), (temp).end());
        combis.insert(temp);
      }
  long long int sizes[8];
  long long int ans, h1, h2, h3;
  vector<int> t1(100000), t2(100000), t3(100000);
  vector<int>::iterator it1, it2, it3;
  auto it = combis.begin();
  cin >> t;
  for (i = 0; i < t; i++) {
    cin >> a >> b >> c;
    ans = 0;
    it1 =
        set_intersection((factors[a]).begin(), (factors[a]).end(),
                         (factors[b]).begin(), (factors[b]).end(), t1.begin());
    it2 =
        set_intersection((factors[b]).begin(), (factors[b]).end(),
                         (factors[c]).begin(), (factors[c]).end(), t2.begin());
    it3 = set_intersection(t1.begin(), it1, t2.begin(), it2, t3.begin());
    sizes[7] = (it3 - t3.begin());
    sizes[6] = (it1 - t1.begin()) - sizes[7];
    sizes[5] = (it2 - t2.begin()) - sizes[7];
    it1 =
        set_intersection((factors[a]).begin(), (factors[a]).end(),
                         (factors[c]).begin(), (factors[c]).end(), t1.begin());
    sizes[4] = (it1 - t1.begin()) - sizes[7];
    sizes[1] = factors[a].size() - sizes[4] - sizes[6] - sizes[7];
    sizes[2] = factors[c].size() - sizes[4] - sizes[5] - sizes[7];
    sizes[3] = factors[b].size() - sizes[5] - sizes[6] - sizes[7];
    for (it = combis.begin(); it != combis.end(); it++) {
      x = (*it)[0];
      y = (*it)[1];
      z = (*it)[2];
      if (x == y && y == z) {
        h1 = sizes[x] * (sizes[x] - 1) * (sizes[x] - 2) / 6;
        h2 = sizes[x] * sizes[x];
        ans += (h1 + h2);
      } else if (x == y)
        ans += (sizes[x] * (sizes[x] + 1) * sizes[z] / 2);
      else if (y == z)
        ans += (sizes[z] * (sizes[z] + 1) * sizes[x] / 2);
      else
        ans += (sizes[x] * sizes[y] * sizes[z]);
    }
    cout << ans << endl;
  }
  return 0;
}
