#include <bits/stdc++.h>
using namespace std;
int uom_cnt;
pair<int, unsigned char> uom[100100];
inline void divisor(int x, int f) {
  int i;
  for (i = 1; i * i <= x; ++i) {
    if (x % i == 0) {
      uom[uom_cnt++] = make_pair(i, f);
      if (i * i != x) {
        uom[uom_cnt++] = make_pair(x / i, f);
      }
    }
  }
}
long long int arr[8];
bitset<2048> bits;
int main() {
  int t;
  long long int s;
  scanf("%d", &t);
  while (t--) {
    uom_cnt = 0;
    memset(arr, 0, 8 * sizeof(long long int));
    s = 0;
    int a, b, c, i;
    scanf("%d%d%d", &a, &b, &c);
    divisor(a, 1);
    divisor(b, 2);
    divisor(c, 4);
    sort(uom, uom + uom_cnt);
    uom[uom_cnt++] = make_pair(-1, -1);
    int last = 0, lastval = -1;
    for (i = 0; i < uom_cnt; ++i) {
      if (lastval != uom[i].first) {
        lastval = uom[i].first;
        ++arr[last];
        last = uom[i].second;
      } else {
        last |= uom[i].second;
      }
    }
    bits.reset();
    for (int i : {1, 3, 5, 7}) {
      for (int j : {2, 3, 6, 7}) {
        for (int k : {4, 5, 6, 7}) {
          int temp[3] = {i, j, k};
          sort(temp, temp + 3);
          int v = (temp[0] << 6) | (temp[1] << 3) | temp[2];
          if (!bits[v]) {
            if (i == j && j == k) {
              s += (arr[i] + 2) * (arr[i] + 1) * arr[i] / 6;
            } else if (i == j) {
              s += (arr[i] + 1) * arr[i] / 2 * arr[k];
            } else if (j == k) {
              s += (arr[j] + 1) * arr[j] / 2 * arr[i];
            } else if (k == i) {
              s += (arr[k] + 1) * arr[k] / 2 * arr[j];
            } else {
              s += arr[i] * arr[j] * arr[k];
            }
            bits[v] = true;
          }
        }
      }
    }
    printf("%lld\n", s);
  }
  return 0;
}
