#include <bits/stdc++.h>
using namespace std;
long long f3(int n) {
  long long ret = 1ll * n * (n - 1) * (n - 2) / 6 + 1ll * n * (n - 1) + 1ll * n;
  return ret;
}
long long f2(int n) { return 1ll * n * (n - 1) / 2 + 1ll * n; }
long long getAns(int a, int b, int c, int ab, int ac, int bc, int abc) {
  long long ret = 0;
  long long m[7] = {a, b, c, ab, ac, bc, abc};
  long long ret1 = 0;
  long long ret2 = 0;
  long long ret3 = 0;
  for (int i = 0; i < 7; i++) {
    for (int j = i + 1; j < 7; j++) {
      for (int k = j + 1; k < 7; k++) {
        ret1 += 1ll * m[i] * m[j] * m[k];
      }
    }
  }
  ret1 -= 1ll * a * b * ab;
  ret1 -= 1ll * a * c * ac;
  ret1 -= 1ll * b * c * bc;
  ret2 += 1ll * f2(ab) * (c + ac + bc + abc);
  ret2 += 1ll * f2(bc) * (a + ab + ac + abc);
  ret2 += 1ll * f2(ac) * (b + ab + bc + abc);
  ret2 += 1ll * f2(abc) * (a + b + c + ab + ac + bc);
  ret3 += f3(abc);
  ret = ret1 + ret2 + ret3;
  return ret;
}
int a[100010];
int b[100010];
int c[100010];
void output(vector<int>& a) {
  for (int i = 0; i < a.size(); i++) {
  }
}
int main() {
  int t;
  scanf("%d", &t);
  vector<int> inA;
  vector<int> inB;
  vector<int> inC;
  vector<int> onlyA;
  vector<int> onlyB;
  vector<int> onlyC;
  vector<int> onlyAB;
  vector<int> onlyAC;
  vector<int> onlyBC;
  vector<int> onlyABC;
  for (int ca = 1; ca <= t; ca++) {
    inA.clear();
    inB.clear();
    inC.clear();
    onlyA.clear();
    onlyB.clear();
    onlyC.clear();
    onlyAB.clear();
    onlyBC.clear();
    onlyAC.clear();
    onlyABC.clear();
    int A, B, C;
    scanf("%d%d%d", &A, &B, &C);
    for (int i = 1; i <= sqrt(A); i++) {
      if (A % i == 0) {
        inA.push_back(i);
        a[i] = ca;
        if (i != A / i) {
          inA.push_back(A / i);
          a[A / i] = ca;
        }
      }
    }
    for (int i = 1; i <= sqrt(B); i++) {
      if (B % i == 0) {
        inB.push_back(i);
        b[i] = ca;
        if (i != B / i) {
          inB.push_back(B / i);
          b[B / i] = ca;
        }
      }
    }
    for (int i = 1; i <= sqrt(C); i++) {
      if (C % i == 0) {
        inC.push_back(i);
        c[i] = ca;
        if (i != C / i) {
          inC.push_back(C / i);
          c[C / i] = ca;
        }
      }
    }
    for (auto x : inA) {
      if (b[x] == ca && c[x] == ca) {
        onlyABC.push_back(x);
      } else if (b[x] != ca && c[x] == ca) {
        onlyAC.push_back(x);
      } else if (b[x] == ca && c[x] != ca) {
        onlyAB.push_back(x);
      } else if (b[x] != ca && c[x] != ca) {
        onlyA.push_back(x);
      }
    }
    for (auto x : inB) {
      if (a[x] != ca) {
        if (c[x] == ca) {
          onlyBC.push_back(x);
        } else {
          onlyB.push_back(x);
        }
      }
    }
    for (auto x : inC) {
      if (a[x] != ca && b[x] != ca) {
        onlyC.push_back(x);
      }
    }
    long long ans =
        getAns(onlyA.size(), onlyB.size(), onlyC.size(), onlyAB.size(),
               onlyAC.size(), onlyBC.size(), onlyABC.size());
    cout << ans << endl;
  }
}
