#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
int yueshu[maxn];
void generator() {
  for (int i = 1; i <= 100000; i++) {
    for (int j = i; j <= 100000; j += i) {
      yueshu[j]++;
    }
  }
}
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
long long jiecheng(int n) {
  long long ans = 1;
  for (long long i = 1; i <= n; i++) {
    ans *= i;
  }
  return ans;
}
long long Cf(int n, int m) {
  long long ans = 1;
  for (int i = n - m + 1; i <= n; i++) {
    ans *= i;
  }
  ans /= jiecheng(m);
  return ans;
}
int main(void) {
  generator();
  int a, b, c;
  int T;
  scanf("%d", &T);
  for (int t = 1; t <= T; t++) {
    scanf("%d%d%d", &a, &b, &c);
    long long ans = yueshu[a] * yueshu[b] * yueshu[c];
    int ab = yueshu[gcd(a, b)];
    int ac = yueshu[gcd(a, c)];
    int bc = yueshu[gcd(b, c)];
    int abc = yueshu[gcd(gcd(a, b), gcd(b, c))];
    int a0 = yueshu[a];
    int b0 = yueshu[b];
    int c0 = yueshu[c];
    int AC = ac - abc;
    int BC = bc - abc;
    int AB = ab - abc;
    int A = yueshu[a] - abc - AC - AB;
    int B = yueshu[b] - abc - AB - BC;
    int C = yueshu[c] - abc - AC - BC;
    int tmp = a0 * b0 * c0 * 6 -
              3 * (a0 * bc * bc + b0 * ac * ac + c0 * ab * ab) +
              6 * (ab * bc * abc + ac * bc * abc + ab * ac * abc) -
              3 * ((ab + bc + ac) * abc * abc) - 6 * ac * ab * bc +
              1 * abc * abc * abc;
    tmp += (AB * (C + BC + AC + abc) + BC * (A + AB + AC + abc) +
            AC * (B + BC + AB + abc) + abc * (abc + AB + AC + BC + A + B + C)) *
           3;
    tmp += abc * 2;
    cout << tmp / 6 << endl;
  }
}
