#include <bits/stdc++.h>
using namespace std;
const int N = 100010, M = 1024;
int t, a, b, c, ans = 0, i, j, k, arr[N], tmp1, tmp2, tmp3, dp[8][8][8], cur[8],
                idx, l;
vector<int> divv[N];
bool A, B, C, can[8][8][8];
int main() {
  int mx = 0;
  for (int i = 1; i < N; i++) {
    for (int j = i; j < N; j += i) divv[j].push_back(i);
  }
  for (int i = 0; i < 8; i++) {
    for (int j = 0; j < 8; j++) {
      for (int k = 0; 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) == 1) && ((v[1] & 2) == 2) && ((v[2] & 4) == 4))
            can[i][j][k] = true;
        } while (next_permutation(v.begin(), v.end()));
      }
    }
  }
  cin >> t;
  while (t--) {
    scanf("%d%d%d", &a, &b, &c);
    idx = i = j = k = 0;
    while (i < (int)divv[a].size() || j < (int)divv[b].size() ||
           k < (int)divv[c].size()) {
      tmp1 = tmp2 = tmp3 = 2000000000;
      if (i < (int)divv[a].size()) tmp1 = divv[a][i];
      if (j < (int)divv[b].size()) tmp2 = divv[b][j];
      if (k < (int)divv[c].size()) tmp3 = divv[c][k];
      if (tmp1 <= tmp2 && tmp1 <= tmp3) {
        if (idx == 0 || arr[idx - 1] < tmp1) arr[idx++] = tmp1;
        i++;
      } else if (tmp2 <= tmp3) {
        if (idx == 0 || arr[idx - 1] < tmp2) arr[idx++] = tmp2;
        j++;
      } else {
        if (idx == 0 || arr[idx - 1] < tmp3) arr[idx++] = tmp3;
        k++;
      }
    }
    memset(cur, 0, sizeof(cur));
    for (i = 0; i < idx; i++) {
      l = 0;
      if (a % arr[i] == 0) l |= 1;
      if (b % arr[i] == 0) l |= 2;
      if (c % arr[i] == 0) l |= 4;
      cur[l]++;
    }
    ans = 0;
    for (int i = 0; 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 && i == k) {
            ans += cur[i] * (cur[i] + 1) * (cur[i] + 2) / 6;
            continue;
          }
          if (i == j && i != k) {
            ans += cur[i] * (cur[i] + 1) / 2 * cur[k];
            continue;
          }
          if (i == k && j != i) {
            ans += cur[i] * (cur[i] + 1) / 2 * cur[j];
            continue;
          }
          if (j == k && i != j) {
            ans += cur[j] * (cur[j] + 1) / 2 * cur[i];
            continue;
          }
          ans += cur[i] * cur[j] * cur[k];
        }
      }
    }
    printf("%d\n", ans);
  }
  return 0;
}
