#include <bits/stdc++.h>
using namespace std;
const int mod = (1e9) + 7;
const double eps = 1e-9;
const int siz = 1e5 + 5, siz2 = 1e5 + 5;
int t, co[siz], v[3], g[8];
vector<int> p[6];
int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b); }
int main() {
  for (int i = 1; i <= 100000; i++) {
    for (long long j = 1; j * j <= i; j++) {
      if (i % j == 0) {
        co[i]++;
        if (j * j != i) {
          co[i]++;
        }
      }
    }
  }
  int c = 0;
  for (int i = 0; i < 3; i++) {
    for (int j = 0; j < 3; j++) {
      if (i == j) {
        continue;
      }
      p[c++] = {i, j, 3 - i - j};
    }
  }
  scanf("%d", &t);
  while (t--) {
    for (int i = 0; i < 3; i++) {
      scanf("%d", &v[i]);
    }
    for (int i = 1; i < 8; i++) {
      for (int j = 0; j < 3; j++) {
        if (i & (1 << j)) {
          g[i] = g[i] != 0 ? gcd(g[i], v[j]) : v[j];
        }
      }
      g[i] = co[g[i]];
    }
    int ans = 0;
    for (int i = 1; i < (1 << 6); i++) {
      int inter[3] = {}, s = 0;
      for (int j = 0; j < 6; j++) {
        if (i & (1 << j)) {
          s++;
          for (int k = 0; k < 3; k++) {
            inter[k] |= (1 << p[j][k]);
          }
        }
      }
      int f = (s & 1) ? 1 : -1;
      ans += f * (g[inter[0]] * g[inter[1]] * g[inter[2]] +
                  g[inter[0] | inter[1]] * g[inter[2]] +
                  g[inter[0] | inter[2]] * g[inter[1]] +
                  g[inter[1] | inter[2]] * g[inter[0]]);
    }
    printf("%d\n", (ans + 2 * g[7]) / 6);
    memset(g, 0, sizeof g);
  }
  return 0;
}
