#include <bits/stdc++.h>
using namespace std;
template <typename T>
void alert(const T &t) {
  cout << t;
  exit(0);
}
template <typename T>
inline void alert(vector<T> &t, char delim = ' ') {
  for (T const &ti : t) cout << ti << delim;
  exit(0);
}
vector<long long> Z(string s) {
  vector<long long> z(s.size());
  long long l = 0, r = 0;
  for (long long i = 1; i < z.size(); i++) {
    if (i >= l && i < r) {
      z[i] = min(z[i - l], r - i);
    }
    while (i + z[i] < z.size() && s[z[i]] == s[i + z[i]]) z[i]++;
    if (i + z[i] > r) {
      l = i;
      r = i + z[i];
    }
  }
  return z;
}
vector<long long> divi(1e5 + 1);
void get_div() {
  for (long long i = 1; i < divi.size(); i++) {
    for (long long j = i; j < divi.size(); j += i) {
      divi[j]++;
    }
  }
}
long long nod(long long a, long long b) {
  if (a > b) swap(a, b);
  while (a > 0) {
    b %= a;
    swap(a, b);
  }
  return b;
}
long long solve(long long &a, long long &b, long long &c) {
  long long A = divi[a], B = divi[b], C = divi[c];
  long long AB = divi[nod(a, b)], AC = divi[nod(a, c)], BC = divi[nod(b, c)];
  long long ABC = divi[nod(a, nod(b, c))];
  long long sum = A * B * C;
  sum -= AB * BC * AC;
  sum += ABC * (AB * BC + BC * AC + AC * AB);
  sum -= A * BC * (BC - 1) / 2 + B * AC * (AC - 1) / 2 + C * AB * (AB - 1) / 2;
  sum -= ABC * (ABC + 1) * (AB + BC + AC) / 2;
  sum += ABC * (ABC + 1) * (ABC + 2) / 6;
  return sum;
}
int main() {
  {
    if ("TASKNAME" != "TASKNAME") {
      freopen(
          "TASKNAME"
          ".in",
          "r", stdin);
      freopen(
          "TASKNAME"
          ".out",
          "w", stdout);
    } else if ("TASKNAME" == "1") {
      freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
    }
  }
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(0);
  long long n;
  cin >> n;
  get_div();
  for (long long i = 0; i < n; i++) {
    long long a, b, c;
    cin >> a >> b >> c;
    cout << solve(a, b, c) << endl;
  }
  return 0;
}
